From bbbc216bb4d4fd8ca95b6c963db925744549c3e1 Mon Sep 17 00:00:00 2001 From: Yann Esposito Date: Mon, 12 Oct 2009 17:36:17 +0200 Subject: [PATCH] =?UTF-8?q?Version=20am=C3=A9lior=C3=A9e,=20en=20cours...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Rules | 6 +++++ config.yaml | 2 +- content/index.html | 2 +- layouts/default.html | 62 ++++++++++++++++++++++++++++---------------- lib/alternate.rb | 6 ++--- lib/default.rb | 2 -- lib/feeds.rb | 8 +++--- lib/helpers.rb | 13 ++++++++++ lib/multi.rb | 48 ++++++++++++++++++++++++++++++++++ 10 files changed, 116 insertions(+), 34 deletions(-) delete mode 100644 lib/default.rb create mode 100644 lib/helpers.rb create mode 100644 lib/multi.rb diff --git a/.gitignore b/.gitignore index 1f71720e4..ce92106f0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ output/Scratch/en output/Scratch/fr output/Scratch/multi output/Scratch/map.yrf +output/index.html tmp/ diff --git a/Rules b/Rules index fed3fe622..a8100e760 100644 --- a/Rules +++ b/Rules @@ -1,6 +1,12 @@ #!/usr/bin/env ruby +# page d'Accueil +route '/' do + '/index.html' +end + # default +# rep => :default est sous-entendu compile '*' do filter :erb layout 'default' diff --git a/config.yaml b/config.yaml index 065fb84f1..a7a92b3bd 100644 --- a/config.yaml +++ b/config.yaml @@ -3,7 +3,7 @@ data_sources: - items_root: / layouts_root: / type: filesystem_combined -output_dir: output/ +output_dir: output # les langues languages: diff --git a/content/index.html b/content/index.html index 7617846b7..8baeebdaf 100644 --- a/content/index.html +++ b/content/index.html @@ -1,5 +1,5 @@ --- -title: Home +title: Titre principal multiTitle: fr: Titre en français en: English Title diff --git a/layouts/default.html b/layouts/default.html index 3273d7408..9028ba396 100644 --- a/layouts/default.html +++ b/layouts/default.html @@ -8,10 +8,20 @@ ----- <% + # -- init variables -- class LocalConf attr_accessor :multi, :blog, :article, :languages, :language, :indent + def to_s + instance_variables.map{ |x| + if instance_variable_get(x).class == Array + %{#{x.intern}= [#{instance_variable_get(x).join(', ')}]} + else + %{#{x.intern}= #{instance_variable_get(x)}} + end + } + end end conf=LocalConf.new @@ -32,16 +42,12 @@ conf.blog=blog languages=@config[:languages] conf.languages=languages +self.instance_variable_set(:@conf, conf) -puts "YYY" -puts %{multi= #{conf.multi}} -puts %{article= #{conf.article}} -puts %{language= #{conf.language}} -puts %{blog= #{conf.blog}} -puts %{languages= [#{conf.languages.join(", ")}]} -puts "YYY" +puts '---' +# puts conf.to_s -%> + %> @@ -51,42 +57,46 @@ puts "YYY" - <%= conf.indent=' '; feeds(conf) %> + <%= conf.indent=' '; feeds %> <% if multi %> - <% alternate(conf) %> + <% alternate %> - Yann Esposito + Yogsototh's Blog <% else %> - Yogsototh's Blog - <%= puts %{multiPageTitle} %> + Yogsototh's Blog - <%= multiPageTitle %> <% end %> <% if multi %> <% end %> -
-

- <%= puts %{multiTitleFor(@page)} %> + <%= multiTitle %>

<% if article or blog %> @@ -96,7 +106,7 @@ puts "YYY" RSS <% end %> <% else %> - RSS + RSS <% end %>
<% end %> @@ -123,6 +133,12 @@ puts "YYY"
+ <% if @item[:content_for_summary] %> +
+ <% @item[:content_for_summary] %> +
+ <% end %> + <% if article and depthOf(@page) == 2 %> <% if hasPrevious(@page) %> <%= previousArticleFor(@page) %> diff --git a/lib/alternate.rb b/lib/alternate.rb index 5a8c30fea..85d490d5d 100644 --- a/lib/alternate.rb +++ b/lib/alternate.rb @@ -1,10 +1,10 @@ -def alternate(conf) +def alternate # need multi to be declared to true when in # multi-language mode false otherwise # languages to the list of available languages # language to the current language - if conf.multi - conf.languages.collect { |lang| %{\n}}.join(conf.indent) + if @conf.multi + @conf.languages.collect { |lang| %{\n}}.join(@conf.indent) else %{} end diff --git a/lib/default.rb b/lib/default.rb deleted file mode 100644 index a4df0ccb7..000000000 --- a/lib/default.rb +++ /dev/null @@ -1,2 +0,0 @@ -# All files in the 'lib' directory will be loaded -# before nanoc starts compiling. diff --git a/lib/feeds.rb b/lib/feeds.rb index cd9038311..ca7126aa4 100644 --- a/lib/feeds.rb +++ b/lib/feeds.rb @@ -1,11 +1,11 @@ -def feeds(conf) +def feeds # need multi to be declared to true when in # multi-language mode false otherwise # languages to the list of available languages # language to the current language - if conf.multi - conf.languages.map { |lang| %{\n} }.join(conf.indent) + if @conf.multi + @conf.languages.map { |lang| %{\n} }.join(@conf.indent) else - %{} + %{} end end diff --git a/lib/helpers.rb b/lib/helpers.rb new file mode 100644 index 000000000..ba38e7add --- /dev/null +++ b/lib/helpers.rb @@ -0,0 +1,13 @@ +# All files in the 'lib' directory will be loaded +# before nanoc starts compiling. + +# Utilisation des helper +# +# ecrire +# <% content_for :summary do %> +# Sommaire que je veux ecrire +# <% end %> +# +# Pour remplir à la fois le texte et le sommaire + +include Nanoc3::Helpers::Capturing diff --git a/lib/multi.rb b/lib/multi.rb new file mode 100644 index 000000000..e6191ec92 --- /dev/null +++ b/lib/multi.rb @@ -0,0 +1,48 @@ +def multiPageTitle + if @conf.multi + @item.title + else + @item[:multiTitle][@conf.language] + end +end + +def multiTitle + multiTitleFor(@item) +end + +def multiTitleFor(item) + begin + if @conf.multi + @conf.languages.map{ |l| %{#{item[:multiTitle][l.intern]}} }.join("\n") + else + item[:multiTitle][@conf.language] + end + rescue + puts "ERROR (lib/multi.rb) certainement pas d'attribut multiTitle" + return item[:title] + end +end + +def tradOf(keyword) + +end + +def tradOfKeywordIn(keyword, language) + begin + @config[:translations][keyword][language.intern] + rescue + if @config[:translations].nil? + puts %{ERROR (lib/multi.rb) Please make a 'translations' hash table in config.yaml} + elsif @config[:translations][keyword].nil? + puts %{ERROR (lib/multi.rb) in config.yaml, + in the 'translations' hash, I can't find the keyword #{keyword}} + elsif @config[:translations][keyword][language.intern].nil? + puts %{ERROR (lib/multi.rb) in config.yaml, + in the 'translations' hash, I can't find the translation + in #{language} for the keyword #{keyword}} + else + puts %{ERROR (lib/multi.rb) erreur inconnue} + end + return '[Sorry Translation Error]' + end +end