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{