Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'nav' of https://github.com/scottfrederick/docs into sco…

…ttfrederick-nav

Conflicts:
	navigation.rb
  • Loading branch information...
commit 939806ee21df2927fd1bed44bd4665127a08fd08 2 parents 73ee5eb + 6df1a13
@scottfrederick scottfrederick authored
Showing with 44 additions and 28 deletions.
  1. +4 −0 config.rb
  2. +0 −28 navigation.rb
  3. +40 −0 quicklinks.rb
View
4 config.rb
@@ -48,6 +48,7 @@
# end
require 'navigation'
+require 'quicklinks'
set :markdown_engine, :redcarpet
set :markdown, :layout_engine => :erb,
@@ -91,6 +92,9 @@
# For navigation breadcrumbs
activate :navigation
+# For generated intra-page links
+activate :quicklinks
+
helpers do
class Middleman::Sitemap::Page
def banner_url
View
28 navigation.rb
@@ -1,8 +1,5 @@
# mostly from https://github.com/multiscan/middleman-navigation but modified slightly
module Navigation
-
- require 'redcarpet'
-
class << self
def registered(app)
app.helpers HelperMethods
@@ -62,31 +59,6 @@ def children_nav(options={})
return content_tag :ul, menu_content, options
end
- def quick_links()
- links = []
- page_src = File.read(current_page.source_file)
- sections = page_src.scan /\n\#{2,3}[^#]+\#{2,3}\n/
-
- markdown = ''
-
- sections.each do |s|
-
- next if s.match(/id='(.+)'/).nil? or s.match(/<\/a>([^#.]+)\#{2,3}/).nil?
-
- anchor_name = s.match(/id='(.+)'/)[1]
- title = s.match(/<\/a>([^#.]+)\#{2,3}/)[1].strip!
- indent = (s.count('#') / 2) - 2
-
- markdown << ' ' * indent
- markdown << "* [#{title}](##{anchor_name})\n"
-
- end
-
- md = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
- result = md.render(markdown)
- "<div class=\"quick-links\">#{result}</div>"
- end
-
# create an <ul> list with links to all the parent pages down to the root
def trail_nav() # removed sep
p = current_page
View
40 quicklinks.rb
@@ -0,0 +1,40 @@
+module QuickLinks
+ require 'redcarpet'
+
+ class << self
+ def registered(app)
+ app.helpers HelperMethods
+ end
+
+ alias :included :registered
+ end
+
+ module HelperMethods
+ def quick_links()
+ links = []
+ page_src = File.read(current_page.source_file)
+ sections = page_src.scan /\n\#{2,3}[^#]+\#{2,3}\n/
+
+ markdown = ''
+
+ sections.each do |s|
+
+ next if s.match(/id=['"](.+)['"]/).nil? or s.match(/<\/a>([^#.]+)\#{2,3}/).nil?
+
+ anchor_name = s.match(/id=['"](.+)['"]/)[1]
+ title = s.match(/<\/a>([^#.]+)\#{2,3}/)[1].strip!
+ indent = (s.count('#') / 2) - 2
+
+ markdown << ' ' * indent
+ markdown << "* [#{title}](##{anchor_name})\n"
+
+ end
+
+ md = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
+ result = md.render(markdown)
+ "<div class=\"quick-links\">#{result}</div>"
+ end
+ end
+end
+
+::Middleman::Extensions.register(:quicklinks, QuickLinks)
Please sign in to comment.
Something went wrong with that request. Please try again.