Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (60 sloc) 2.052 kb
d16d9eb @winton More work on web site
authored
1 require 'albino'
f670b8b @winton Working on official Stasis site
authored
2 require 'nokogiri'
3
4 before 'index.html.haml' do
a7cad8a @winton Updating README, gemspec fixes
authored
5 @readme = render('../README.md')
6 @readme = Nokogiri::HTML(@readme).css('body')
d16d9eb @winton More work on web site
authored
7
8 # Remove everything before the first <h2> tag
f670b8b @winton Working on official Stasis site
authored
9 @readme.children.each do |node|
10 break if node.name == 'h2'
11 node.remove
12 end
d16d9eb @winton More work on web site
authored
13
a880da8 @winton More work on web site
authored
14 # Link <h2> and <h3> tags
15 @links = @readme.css('h2, h3').collect do |node|
16 href = node.text.downcase.gsub(/\s/, '_')
d16d9eb @winton More work on web site
authored
17 name = node.text
18 node.inner_html = '<a name="' + href + '" href="#' + href + '">' + node.inner_html + '</a>'
a880da8 @winton More work on web site
authored
19 if node.name == 'h2'
20 { :name => name, :href => href }
21 else
22 nil
23 end
d16d9eb @winton More work on web site
authored
24 end
a880da8 @winton More work on web site
authored
25 @links.compact!
d16d9eb @winton More work on web site
authored
26
27 @readme.css('pre').each do |pre|
28
a7cad8a @winton Updating README, gemspec fixes
authored
29 # Retrieve language and highlight info from comment
a880da8 @winton More work on web site
authored
30 highlight = nil
d16d9eb @winton More work on web site
authored
31 language = nil
32 comment = pre.previous.previous
33 if comment && comment.comment?
a880da8 @winton More work on web site
authored
34 highlight = comment.content.match(/highlight:(\S+)/)
35 language = comment.content.match(/language:(\S+)/)
36 highlight = highlight[1].split(',') if highlight
37 language = language[1] if language
d16d9eb @winton More work on web site
authored
38 end
a880da8 @winton More work on web site
authored
39 highlight ||= []
d16d9eb @winton More work on web site
authored
40 language ||= :ruby
41
42 # Insert <pre> tags before the previous element (because its floated right)
43 unless pre.previous_element.name == 'h2'
44 pre.previous_element.add_previous_sibling(pre)
45 end
46
47 # Insert <div class="clear"> before each <pre> tag
48 pre.add_previous_sibling('<div class="clear"></div>')
49
50 # Pygmentize
a880da8 @winton More work on web site
authored
51 pygmented = Albino.colorize(pre.css('code').text, language)
52
53 # Highlight
54 highlight.each do |str|
55 pygmented = pygmented.gsub(str, '<span class="sr">' + str + '</span>')
56 end
57
58 # Replace <pre>
59 pre.replace pygmented
d16d9eb @winton More work on web site
authored
60 end
61
62 # Insert <div class="clear"> before each <h3> tag
63 @readme.css('h3').each do |h3|
64 h3.add_previous_sibling('<div class="clear"></div>')
65 end
66
67 # Replace colons at the end of <p> tags with arrows.
68 @readme.css('p').each do |p|
69 p.inner_html = p.inner_html.strip.gsub(/:$/, '<img src="arrow.png" class="arrow" />')
70 end
71
f670b8b @winton Working on official Stasis site
authored
72 @readme = @readme.inner_html
73 end
Something went wrong with that request. Please try again.