From 143f6521e5d7fc5553373a2a0fb9808d73a26cce Mon Sep 17 00:00:00 2001 From: Eric Redmond Date: Thu, 20 Dec 2012 13:01:22 -0800 Subject: [PATCH] Add i18n and clean up config --- config.rb | 127 ++++-------------------------- data/global_nav.yml | 1 + deploy.rb | 2 + lib/deploy.rb | 2 + lib/duals.rb | 16 ++++ lib/env.rb | 18 +++++ lib/faqml.rb | 33 ++++---- locales/en.yml | 27 +++++++ locales/jp.yml | 27 +++++++ source/css/common.css.scss | 3 +- source/layouts/_footer.slim | 6 +- source/layouts/_header.slim | 8 +- source/layouts/_keywords.slim | 2 +- source/layouts/_primary.slim | 11 ++- source/layouts/_secondary.slim | 9 +-- source/layouts/_tutorial_nav.slim | 6 +- source/layouts/layout.slim | 10 +-- 17 files changed, 149 insertions(+), 159 deletions(-) create mode 100644 lib/duals.rb create mode 100644 lib/env.rb create mode 100644 locales/en.yml create mode 100644 locales/jp.yml diff --git a/config.rb b/config.rb index 1028dc48af..4deb1d97bc 100644 --- a/config.rb +++ b/config.rb @@ -1,93 +1,22 @@ require 'aws/s3' require 'versionomy' +require './lib/env' require './lib/org' require './lib/versionify' require './lib/faqml' -require './lib/rocco' require './lib/deploy' require './lib/index' require './lib/sitemap_render_override' +require './lib/duals' -if ENV['RIAK_VERSION'].blank? || ENV['RIAK_VERSION'] !~ /[\d\.]+/ - versions = YAML::load(File.open('data/versions.yml')) - for proj, vs in versions['currents'] - proj = proj.upcase - ENV["#{proj}_VERSION"] = vs - puts "#{proj}_VERSION=#{ENV["#{proj}_VERSION"]}" - end -end - -$versions = { - :riak => ENV['RIAK_VERSION'].presence, - :riakcs => ENV['RIAKCS_VERSION'].presence || ENV['RIAK_VERSION'].presence, - :riakee => ENV['RIAKEE_VERSION'].presence || ENV['RIAK_VERSION'].presence -} - -use Rack::Middleman::VersionRouter #if $versions[:riak].present? - -# this is not optimal. Hook it into the "watch" mechanism -puts "== Generating API" -for api in Dir.glob("**/*.api") - r = Rocco.new(api, [], :language => 'bash', :template_file => './source/layouts/api.mustache') #{File.read(api)} - File.open(api.sub(/\.api$/, '.html.erb'), 'w') do |html| - html.write(r.to_html) - end -end -for api in Dir.glob("**/*.roc") - r = DocRocco.new(api, [], :language => 'bash', :template_file => './source/layouts/roc.mustache') #{File.read(api)} - File.open(api.sub(/\.roc$/, '.html.erb'), 'w') do |html| - html.write(r.to_html) - end -end - -### -# Compass -### - -# Susy grids in Compass -# First: gem install compass-susy-plugin -# require 'susy' - -# Change Compass configuration -# compass_config do |config| -# config.output_style = :compact -# end - -### -# Page options, layouts, aliases and proxies -### - -# Per-page layout changes: -# -# With no layout -# page "/path/to/file.html", :layout => false -# -# With alternative layout -# page "/path/to/file.html", :layout => :otherlayout -# -# A path which all have the same layout -# with_layout :admin do -# page "/admin/*" -# end - -page "/404.html", :directory_index => false +# since we're using ERB to dynamically generate this, MM assumes it's html page "/js/standalone/version-bar.js", :proxy => "js/standalone/version-bar.html", :directory_index => false, :ignore => true +page "/404.html", :directory_index => false - -# Proxy (fake) files -# page "/this-page-has-no-template.html", :proxy => "/template-file.html" do -# @which_fake_page = "Rendering a fake page with a variable" -# end - -# page "/tutorials/*", :layout => 'layouts/layout' - -# Register the FML plugin to middleman -Middleman::Application.register Middleman::Renderers::FAQML -# Middleman::Application.register Middleman::Renderers::Rocco - - -############# -# override tha languages to manage versions!? +%w{riak riakcs riakee}.each do |project| + version = $versions[project.to_sym] + page "/#{project}/#{version}/index.html", :proxy => "/#{project}-index.html", :directory_index => false, :ignore => true +end def build_keyword_pages keyword_pages = {} @@ -110,14 +39,6 @@ def build_keyword_pages end end - # for api in Dir.glob("**/*.api") - # page api.sub(/\.?\/?source/, '').sub(/\.api$/, '.html'), :layout => false - # end - - # for api in Dir.glob("**/*.roc") - # page api.sub(/\.?\/?source/, '').sub(/\.roc$/, '.html'), :layout => false - # end - if ENV.include?('INDEX') puts "== Indexing" build_yokozuna_index(sitemap.resources) @@ -264,53 +185,33 @@ def build_nav(section, c_name='', depth=1) # Automatic image dimensions on image_tag helper # activate :automatic_image_sizes -# require 'rack/codehighlighter' -# require "pygments" -# use Rack::Codehighlighter, -# :pygments, -# :element => "pre>code", -# :pattern => /\A:::([-_+\w]+)\s*\n/, -# :markdown => true - +# set language set :css_dir, 'css' set :js_dir, 'js' set :images_dir, 'images' - set :markdown_engine, :redcarpet set :markdown, :fenced_code_blocks => true, :smartypants => true, :tables => true, :no_intra_emphasis => true, :lax_html_blocks => true - # :autolink => true, - # :with_toc_data => true +use Rack::Middleman::VersionRouter + +activate :faqml activate :directory_indexes activate :versionify - -%w{riak riakcs riakee}.each do |project| - version = $versions[project.to_sym] || ENV['RIAK_VERSION'] - page "/#{project}/#{version}/index.html", :proxy => "/#{project}-index.html", :directory_index => false, :ignore => true -end - +activate :i18n activate :cache_buster activate :relative_assets # Build-specific configuration configure :build do - activate Middleman::Features::ProductionCheck - + activate :production_check #Middleman::Features::ProductionCheck activate :minify_css activate :minify_javascript # activate :gzip - # activate :cache_buster - # activate :relative_assets - - # Compress PNGs after build - # require "middleman-smusher" - # activate :smusher - ignore "source/images/layout/*.png" activate :version_dirs diff --git a/data/global_nav.yml b/data/global_nav.yml index 2f49c970b0..f9b301a41a 100644 --- a/data/global_nav.yml +++ b/data/global_nav.yml @@ -139,6 +139,7 @@ riak: - title: "FAQs" sub: - "[[All FAQs|FAQs]]" + - "[[The Basics|Basic FAQs]]" - "[[Developing on Riak|Developing on Riak FAQs]]" - "[[Operating Riak|Operating Riak FAQs]]" - "[[Log Messages|Log Messages FAQs]]" diff --git a/deploy.rb b/deploy.rb index 460e120e90..a72542ee1f 100755 --- a/deploy.rb +++ b/deploy.rb @@ -10,6 +10,8 @@ exit(0) end +ENV['RIAK_DOCS_LANG'] = 'en' + `rm -rf build` ENV['RIAK_VERSION'] = ARGV[0] ENV['RIAKCS_VERSION'] = ARGV[1] || ARGV[0] diff --git a/lib/deploy.rb b/lib/deploy.rb index 8a1ad4d38a..ad8aba1def 100644 --- a/lib/deploy.rb +++ b/lib/deploy.rb @@ -114,3 +114,5 @@ def registered(app) end end end + +::Middleman::Extensions.register(:production_check, ::Middleman::Features::ProductionCheck) diff --git a/lib/duals.rb b/lib/duals.rb new file mode 100644 index 0000000000..1a8addf89a --- /dev/null +++ b/lib/duals.rb @@ -0,0 +1,16 @@ +require './lib/rocco' + +# this is not optimal. Hook it into the "watch" mechanism +puts "== Generating DUAL Pages" +for api in Dir.glob("**/*.api") + r = Rocco.new(api, [], :language => 'bash', :template_file => './source/layouts/api.mustache') + File.open(api.sub(/\.api$/, '.html.erb'), 'w') do |html| + html.write(r.to_html) + end +end +for api in Dir.glob("**/*.roc") + r = DocRocco.new(api, [], :language => 'bash', :template_file => './source/layouts/roc.mustache') + File.open(api.sub(/\.roc$/, '.html.erb'), 'w') do |html| + html.write(r.to_html) + end +end diff --git a/lib/env.rb b/lib/env.rb new file mode 100644 index 0000000000..8c8c2b323b --- /dev/null +++ b/lib/env.rb @@ -0,0 +1,18 @@ +LANGUAGE = (ENV['RIAK_DOCS_LANG'] || 'en').to_sym +puts "RIAK_DOCS_LANG=#{LANGUAGE}" +I18n.locale = I18n.default_locale = LANGUAGE + +if ENV['RIAK_VERSION'].blank? || ENV['RIAK_VERSION'] !~ /[\d\.]+/ + versions = YAML::load(File.open('data/versions.yml')) + for proj, vs in versions['currents'] + proj = proj.upcase + ENV["#{proj}_VERSION"] = vs + puts "#{proj}_VERSION=#{ENV["#{proj}_VERSION"]}" + end +end + +$versions = { + :riak => ENV['RIAK_VERSION'].presence, + :riakcs => ENV['RIAKCS_VERSION'].presence || ENV['RIAK_VERSION'].presence, + :riakee => ENV['RIAKEE_VERSION'].presence || ENV['RIAK_VERSION'].presence +} diff --git a/lib/faqml.rb b/lib/faqml.rb index 9581968d24..8dd9875acc 100644 --- a/lib/faqml.rb +++ b/lib/faqml.rb @@ -1,22 +1,23 @@ module Middleman::Renderers::FAQML - def registered(app) - # FAQML is not included in the default gems, - # but we'll support it if available. - begin - # Load gem - require "faqml" - - app.before_configuration do - template_extensions :fml => :html + class << self + def registered(app) + begin + require "faqml" + app.before_configuration do + template_extensions :fml => :html + end + # Setup FAQML options to work with partials + ::FAQML::Engine.set_default_options( + :buffer => '@_out_buf', + :generator => ::Temple::Generators::StringBuffer + ) + rescue LoadError + puts "Error Loading FAQML" end - - # Setup FAQML options to work with partials - ::FAQML::Engine.set_default_options( - :buffer => '@_out_buf', - :generator => ::Temple::Generators::StringBuffer - ) - rescue LoadError end + alias :included :registered end end + +::Middleman::Extensions.register(:faqml, Middleman::Renderers::FAQML) diff --git a/locales/en.yml b/locales/en.yml new file mode 100644 index 0000000000..1e4d73cf03 --- /dev/null +++ b/locales/en.yml @@ -0,0 +1,27 @@ +--- +en: + basho: Basho + visit_basho: Visit Basho + home: Home + riak_docs: Riak Docs + tagline: "Product tutorials, how-tos, and fully-documented APIs." + keywords: Keywords + navigation: Navigation + all_projects: All Riak Projects + docs_on_github: "These docs are available on GitHub. Please submit ideas and patches." + secondary_header: "These May Also Interest You" + faqs_link: "[[FAQs]]" + apis_link: "[[APIs]]" + tutorial_nav: "Tutorial Nav" + previous: Prev + next: Next + toc_contents: Contents + footer: "This work is licensed under a Creative Commons Attribution 3.0 Unported License" + riak_cs: + info: + title: Riak CS Only + body: "To try out Riak CS, sign up for a developer trial." + riak_ee: + info: + title: Riak Enterprise Only + body: "This documentation applies only to Riak Enterprise, Basho's commercial extension to [[Riak]]. To talk to us about using Riak Enterprise, let us know." diff --git a/locales/jp.yml b/locales/jp.yml new file mode 100644 index 0000000000..c154786b4d --- /dev/null +++ b/locales/jp.yml @@ -0,0 +1,27 @@ +--- +jp: + basho: Bashosan + visit_basho: Visit Bashosan + home: Home + riak_docs: Riak Docs + tagline: "Product tutorials, how-tos, and fully-documented APIs." + keywords: Keywords + navigation: Navigation + all_projects: All Riak Projects + docs_on_github: "These docs are available on GitHub. Please submit ideas and patches." + secondary_header: "These May Also Interest You" + faqs_link: "[[FAQs]]" + apis_link: "[[APIs]]" + tutorial_nav: "Tutorial Nav" + previous: Prev + next: Next + toc_contents: Contents + footer: "This work is licensed under a Creative Commons Attribution 3.0 Unported License" + riak_cs: + info: + title: Riak CS Only + body: "To try out Riak CS, sign up for a developer trial." + riak_ee: + info: + title: Riak Enterprise Only + body: "This documentation applies only to Riak Enterprise, Basho's commercial extension to [[Riak]]. To talk to us about using Riak Enterprise, let us know." diff --git a/source/css/common.css.scss b/source/css/common.css.scss index 49d7e4a652..3d005c1aea 100644 --- a/source/css/common.css.scss +++ b/source/css/common.css.scss @@ -663,8 +663,7 @@ div[role="main"] { .logo { margin-top : 5px; @include size(200px, 33px); - // Deprecated behavior, but what other options do we have? - @include layout-sprite(logo2); + background: url(../images/layout/logo2.png) } } diff --git a/source/layouts/_footer.slim b/source/layouts/_footer.slim index 8fc488a8d2..ede65c0488 100644 --- a/source/layouts/_footer.slim +++ b/source/layouts/_footer.slim @@ -1,6 +1,4 @@ footer.mastfooter - | This work is licensed under a - a href="http://creativecommons.org/licenses/by/3.0/" target="_blank" - | Creative Commons Attribution 3.0 Unported License + == I18n.t(:footer) br - | Copyright © #{Date.today.year} Basho Technologies, Inc. All rights reserved. + | © 2011-#{Date.today.year} Basho Technologies, Inc. diff --git a/source/layouts/_header.slim b/source/layouts/_header.slim index 2cf2205465..61da2de2d4 100644 --- a/source/layouts/_header.slim +++ b/source/layouts/_header.slim @@ -2,10 +2,10 @@ header.masthead div#top-nav form action="http://search.basho.com" input#main-search size="5" type="search" placeholder="Search" name="q" - a href="/index.html" Home - a href="http://www.basho.com" Basho + a href="/index.html"== I18n.t(:home) + a href="http://www.basho.com"== I18n.t(:basho) a.responsive-toggle a.logo href="/index.html" - h1 Riak Docs - span.tagline Product tutorials, how-tos, and fully-documented APIs. + h1== I18n.t(:riak_docs) + span.tagline== I18n.t(:tagline) img.shadow-divider(src="/images/layout/shadow-divider.png") diff --git a/source/layouts/_keywords.slim b/source/layouts/_keywords.slim index 411b252328..5035495ae2 100644 --- a/source/layouts/_keywords.slim +++ b/source/layouts/_keywords.slim @@ -1,3 +1,3 @@ - if data.page.keywords.present? - h4 Keywords + h4== I18n.t(:keywords) == data.page.keywords.map{|kw| ""+kw+""}.join(', ') diff --git a/source/layouts/_primary.slim b/source/layouts/_primary.slim index 42e099f6f4..e08ff14250 100644 --- a/source/layouts/_primary.slim +++ b/source/layouts/_primary.slim @@ -1,12 +1,12 @@ aside#nav-container role="complementary" nav.overview#primary-nav role="nav" h2.responsive-link - | Navigation + == I18n.t(:navigation) a.responsive-toggle h3.responsive-link.visit-basho - a href="http://www.basho.com" Visit Basho + a href="http://www.basho.com"== I18n.t(:visit_basho) h3.responsive-link - a href="/index.html" All Riak Projects + a href="/index.html"== I18n.t(:all_projects) - project = data.page.project || 'riak' - data.global_nav[project].each do |section| - add_class = section['class'] || '' @@ -14,7 +14,6 @@ aside#nav-container role="complementary" h3(class=(active ? "active #{add_class}" : add_class)) span==section['title'] ==nav_data - .submissions-note - a(href='https://github.com/basho/basho_docs' target='_blank') - | These docs are available on GitHub. Please submit ideas and patches. + a href='https://github.com/basho/basho_docs' target='_blank' + == I18n.t(:docs_on_github) diff --git a/source/layouts/_secondary.slim b/source/layouts/_secondary.slim index ac05ddcef7..99590072d7 100644 --- a/source/layouts/_secondary.slim +++ b/source/layouts/_secondary.slim @@ -1,14 +1,13 @@ - section.right-sidebar aside.secondary role="complementary" nav role="nav" - h4 These May Also Interest You + h4== I18n.t(:secondary_header) ul - if (pages = similar_pages(current_resource)).present? - for page in pages[0..5] li== "[[#{page.metadata[:page]['title']}]]" - else - li== link_to 'All Riak Projects', '/index.html' - li [[FAQs]] - li [[APIs]] + li== link_to I18n.t(:all_projects), '/index.html' + li==I18n.t(:faqs_link) + li==I18n.t(:apis_link) == partial "layouts/keywords" diff --git a/source/layouts/_tutorial_nav.slim b/source/layouts/_tutorial_nav.slim index 050f0ccbb7..79b778c0f5 100644 --- a/source/layouts/_tutorial_nav.slim +++ b/source/layouts/_tutorial_nav.slim @@ -1,7 +1,7 @@ - if data.page.prev.present? || data.page.up.present? || data.page.next.present? nav.tutorial h4 - | Tutorial Nav + == I18n.t(:tutorial_nav) - if data.page.up.present? | :  span.up @@ -9,9 +9,9 @@ ul - if data.page.prev.present? li.prev - span.label Prev + span.label== I18n.t(:previous) ==link_to data.page.prev.first, data.page.prev.last - if data.page.next.present? li.next - span.label Next + span.label == I18n.t(:next) ==link_to data.page.next.first, data.page.next.last diff --git a/source/layouts/layout.slim b/source/layouts/layout.slim index c59ccab983..f35ed4f4b4 100644 --- a/source/layouts/layout.slim +++ b/source/layouts/layout.slim @@ -37,17 +37,17 @@ body class=classnames.join(' ') id=data.page.body_id == partial "layouts/breadcrumb_nav" unless data.page.project == 'shared' - if data.page.project == 'riakcs' .info - .title Riak CS Only - | To try out Riak CS, sign up for a developer trial. + .title== I18n.t(:"riak_cs.info.title") + == I18n.t(:"riak_cs.info.body") - if data.page.project == 'riakee' .info - .title Riak Enterprise Only - | This documentation applies only to Riak Enterprise, Basho's commercial extension to [[Riak]]. To talk to us about using Riak Enterprise, let us know. + .title== I18n.t(:"riak_ee.info.title") + == I18n.t(:"riak_ee.info.body") - unless data.page.toc == false nav#toc - h2.title Contents + h2.title== I18n.t(:toc_contents) div#toc-wrapper ol#toc-items == yield