Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem "thin"
gem "rack"
gem "listen"
gem "builder"
gem "grit"

group :development do
gem "pry"
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -132,6 +139,7 @@ DEPENDENCIES
activesupport
builder
coderay!
grit
highline
listen
middleman (~> 3.0)
Expand Down
46 changes: 44 additions & 2 deletions config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'redcarpet'
require 'active_support/core_ext'


Dir['./lib/*'].each { |f| require f }

# Debugging
Expand Down Expand Up @@ -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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And doing the same on the guides directory.

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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the index.

end

page 'community.html'
Expand Down
3 changes: 3 additions & 0 deletions data/guide_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Current: Edge
Edge: master
Old: 4de6feab9c2a
12 changes: 6 additions & 6 deletions lib/toc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def index_for(data)

result << %Q{
<li class="level-1#{current ? ' selected' : ''}">
<a href="/guides/#{entries[0].url}">#{section}</a>
<a href="/guides/#{@sha}/#{entries[0].url}">#{section}</a>
<ol#{current ? " class='selected'" : ''}>
}

Expand All @@ -54,7 +54,7 @@ def index_for(data)

result << %Q{
<li class="level-3#{sub_current ? ' sub-selected' : ''}">
<a href="/guides/#{entry.url}">#{entry.title}</a>
<a href="/guides/#{@sha}/#{entry.url}">#{entry.title}</a>
</li>
}
end
Expand All @@ -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|
Expand Down Expand Up @@ -121,7 +121,7 @@ def chapter_links
def previous_chapter_link
return '' unless previous_chapter
%Q{
<a class="previous-guide" href="/guides/#{previous_chapter.url}">
<a class="previous-guide" href="/guides/#{@sha}/#{previous_chapter.url}">
\u2190 #{previous_chapter.title}
</a>
}
Expand All @@ -130,7 +130,7 @@ def previous_chapter_link
def next_chapter_link
return '' unless next_chapter
%Q{
<a class="next-guide" href="/guides/#{next_chapter.url}">
<a class="next-guide" href="/guides/#{@sha}/#{next_chapter.url}">
#{next_chapter.title} \u2192
</a>
}
Expand Down
1 change: 1 addition & 0 deletions source/guides/versioned.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render_individual_file @path, nil, :template_body => @template %>
2 changes: 1 addition & 1 deletion source/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<a id="logo" href="/">&nbsp;</a>
<ul id="nav">
<%= link_to_page "about", "/about" %>
<%= link_to_page "guides", "/guides" %>
<%= link_to_page "guides", "/guides/#{data.guide_versions[data.guide_versions["Current"]]}" %>
<%= link_to_page "api", "/api" %>
<%= link_to_page "community", "/community" %>
<%= link_to_page "blog", "/blog" %>
Expand Down
9 changes: 8 additions & 1 deletion source/layouts/guide.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
%>

<% wrap_layout(:layout) do %>
<nav>
<% data.guide_versions.each do |name, sha| %>
<% next if name == "Current" %>
<a href="/guides/<%= sha %>"><%= name %></a>
<% end %>
</nav>

<% content_for(:sidebar) do %>
<%= index_for(data.guides) %>
<%= index_for(@guides) %>
<% end %>

<div class="chapter">
Expand Down