From 9a10454076031345d851f29be141e84264798e0d Mon Sep 17 00:00:00 2001 From: Collin Miller Date: Mon, 25 Feb 2013 01:36:47 -0600 Subject: [PATCH] re created versioned guides for master --- Gemfile | 1 + Gemfile.lock | 8 ++++++ config.rb | 46 ++++++++++++++++++++++++++++++-- data/guide_versions.yml | 3 +++ lib/toc.rb | 12 ++++----- source/guides/versioned.html.erb | 1 + source/layout.erb | 2 +- source/layouts/guide.erb | 9 ++++++- 8 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 data/guide_versions.yml create mode 100644 source/guides/versioned.html.erb diff --git a/Gemfile b/Gemfile index 4b6b0812b7..d745fc2fa2 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem "thin" gem "rack" gem "listen" gem "builder" +gem "grit" group :development do gem "pry" diff --git a/Gemfile.lock b/Gemfile.lock index 931e9bccff..79afc40728 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,11 +22,16 @@ GEM fssm (>= 0.2.7) sass (~> 3.1) daemons (1.1.8) + diff-lcs (1.1.3) eventmachine (0.12.10) execjs (1.4.0) multi_json (~> 1.0) ffi (1.4.0) fssm (0.2.10) + grit (2.5.0) + diff-lcs (~> 1.1) + mime-types (~> 1.15) + posix-spawn (~> 0.3.6) haml (4.0.0) tilt highline (1.6.13) @@ -73,6 +78,7 @@ GEM middleman-more (>= 3.0.1) sprockets (~> 2.1, < 2.5) sprockets-sass (~> 0.9.0) + mime-types (1.21) multi_json (1.6.1) padrino-core (0.10.7) activesupport (~> 3.2.0) @@ -83,6 +89,7 @@ GEM padrino-helpers (0.10.7) i18n (~> 0.6) padrino-core (= 0.10.7) + posix-spawn (0.3.6) pry (0.9.10) coderay (~> 1.0.5) method_source (~> 0.8) @@ -132,6 +139,7 @@ DEPENDENCIES activesupport builder coderay! + grit highline listen middleman (~> 3.0) diff --git a/config.rb b/config.rb index ac888e5a76..f0baeb97c3 100644 --- a/config.rb +++ b/config.rb @@ -1,6 +1,7 @@ require 'redcarpet' require 'active_support/core_ext' + Dir['./lib/*'].each { |f| require f } # Debugging @@ -36,8 +37,49 @@ # Pages ### -page 'guides*', layout: :guide do - @guides = data.guides +repo = Grit::Repo.new( + File.join( File.dirname(__FILE__), ".git" ) +) + +def reach_into_guides(content, path=[], &block) + if content.is_a? Grit::Tree + content.contents.each do |sub_content| + reach_into_guides(sub_content, path.dup << content.name, &block) + end + elsif content.is_a? Grit::Blob + if content.name == "index.md" && path[1] + yield "#{path * '/'}", content.data + else + yield "#{path * '/'}/#{content.name}".sub('.md', ''), content.data + end + end +end + +data.guide_versions.each do |name, sha| + next if name == "Current" + commit = repo.commits(sha).first + guides_data = ::Middleman::Util.recursively_enhance( + YAML.load (commit.tree / "data" / "guides.yml").data + ) + tree = commit.tree / "source" / "guides" + reach_into_guides(tree) do |path, data_at_sha| + sha_path = path.dup.sub("guides/", "guides/#{sha}/") + page sha_path, + :proxy => "guides/versioned.html", + :layout => "guide" do + @guides = guides_data + @template = data_at_sha + @path = path + ".md" + @sha = sha + end + end + + page "/guides/#{sha}", + :proxy => "guides/index.html", + :layout => "guide" do + @guides = guides_data + @sha = sha + end end page 'community.html' diff --git a/data/guide_versions.yml b/data/guide_versions.yml new file mode 100644 index 0000000000..5a9c594312 --- /dev/null +++ b/data/guide_versions.yml @@ -0,0 +1,3 @@ +Current: Edge +Edge: master +Old: 4de6feab9c2a \ No newline at end of file diff --git a/lib/toc.rb b/lib/toc.rb index 60a6f24633..3961551b67 100644 --- a/lib/toc.rb +++ b/lib/toc.rb @@ -37,7 +37,7 @@ def index_for(data) result << %Q{
  • - #{section} + #{section} } @@ -54,7 +54,7 @@ def index_for(data) result << %Q{
  • - #{entry.title} + #{entry.title}
  • } end @@ -68,9 +68,9 @@ def index_for(data) end def chapter_name - guides = data.guides + guides = @guides - sub_url = request.path.split('/')[1] + sub_url = request.path.split('/')[2] heading = '' guides.each_entry do |section, entries| @@ -121,7 +121,7 @@ def chapter_links def previous_chapter_link return '' unless previous_chapter %Q{ - + \u2190 #{previous_chapter.title} } @@ -130,7 +130,7 @@ def previous_chapter_link def next_chapter_link return '' unless next_chapter %Q{ - + #{next_chapter.title} \u2192 } diff --git a/source/guides/versioned.html.erb b/source/guides/versioned.html.erb new file mode 100644 index 0000000000..cc65bb38cf --- /dev/null +++ b/source/guides/versioned.html.erb @@ -0,0 +1 @@ +<%= render_individual_file @path, nil, :template_body => @template %> \ No newline at end of file diff --git a/source/layout.erb b/source/layout.erb index 83a0264dd9..3f8ac0ec5d 100644 --- a/source/layout.erb +++ b/source/layout.erb @@ -81,7 +81,7 @@