You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/01/28 01:40:27 UTC
[5/7] git commit: Auto-generate the navigation bar from index.html
Auto-generate the navigation bar from index.html
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/commit/53fef6b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/tree/53fef6b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/diff/53fef6b9
Branch: refs/heads/master
Commit: 53fef6b900518c3d150f72353db8be75feee7f11
Parents: 53cf985
Author: Michael Brooks <mi...@michaelbrooks.ca>
Authored: Thu Jan 26 20:54:00 2012 -0800
Committer: Fil Maj <fi...@nitobi.com>
Committed: Fri Jan 27 16:38:38 2012 -0800
----------------------------------------------------------------------
lib/phonegap/navigation_menu.rb | 45 +++++++++++++++++++++++++++------
template/docs/default/index.html | 6 ----
template/docs/es/index.html | 6 ----
template/docs/fr/index.html | 6 ----
template/docs/jp/index.html | 6 ----
5 files changed, 37 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/blob/53fef6b9/lib/phonegap/navigation_menu.rb
----------------------------------------------------------------------
diff --git a/lib/phonegap/navigation_menu.rb b/lib/phonegap/navigation_menu.rb
index 349726e..ebc233f 100644
--- a/lib/phonegap/navigation_menu.rb
+++ b/lib/phonegap/navigation_menu.rb
@@ -8,25 +8,54 @@ class NavigationMenu
include FileHelpers
def initialize(options = {})
+ @sections = []
+
filename = Dir.glob(File.join tmp_directory, '**', 'index.md.html')[0]
- doc = Nokogiri::HTML(File.read(filename))
- @li_set = Nokogiri::XML::NodeSet.new doc
+ doc = Nokogiri::HTML(File.read(filename))
- doc.css('ul:first h2 a').each do |element|
- li = Nokogiri::XML::Node.new 'li', doc
- li.add_child element
- @li_set.push li
+ h1_set = doc.css('#home > h1')
+ ul_set = doc.css('#home > ul')
+ count = h1_set.count
+
+ count.times do |index|
+ links = []
+ ul_set[index].css('li > h2 > a').each { |a| links.push(a) }
+
+ @sections.push({
+ 'title' => h1_set[index].text,
+ 'links' => links
+ })
end
end
def run(filename)
doc = Nokogiri::HTML(File.read(filename))
- ul_element = doc.css('#sidebar ul:first')[0]
- ul_element.add_child @li_set
+ @sections.each do |section|
+ insert_title(section['title'], doc)
+ insert_links(section['links'], doc)
+ end
File.open(filename, 'w') { |file| file.write doc.to_html }
return doc.to_html
end
+
+ def insert_title(title, doc)
+ h1 = Nokogiri::XML::Node.new 'h1', doc
+ h1.content = title
+ doc.css('#sidebar').first.add_child(h1)
+ end
+
+ def insert_links(links, doc)
+ ul = Nokogiri::XML::Node.new 'ul', doc
+
+ links.each do |link|
+ li = Nokogiri::XML::Node.new 'li', doc
+ li.add_child(link)
+ ul.add_child(li)
+ end
+
+ doc.css('#sidebar').first.add_child(ul)
+ end
end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/blob/53fef6b9/template/docs/default/index.html
----------------------------------------------------------------------
diff --git a/template/docs/default/index.html b/template/docs/default/index.html
index fc5899e..cbc116d 100644
--- a/template/docs/default/index.html
+++ b/template/docs/default/index.html
@@ -25,12 +25,6 @@
<div id="sidebar">
<div class="vertical_divider"></div>
- <h1>API Reference</h1>
- <ul></ul>
- <h1></h1>
- <ul>
- <li><a href="_index.html">Keyword Index</a></li>
- </ul>
</div>
<div id="scrollable">
http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/blob/53fef6b9/template/docs/es/index.html
----------------------------------------------------------------------
diff --git a/template/docs/es/index.html b/template/docs/es/index.html
index 8130624..7a7895f 100644
--- a/template/docs/es/index.html
+++ b/template/docs/es/index.html
@@ -25,12 +25,6 @@
<div id="sidebar">
<div class="vertical_divider"></div>
- <h1>Referencia API</h1>
- <ul></ul>
- <h1></h1>
- <ul>
- <li><a href="_index.html">Índice por palabras</a></li>
- </ul>
</div>
<div id="scrollable">
http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/blob/53fef6b9/template/docs/fr/index.html
----------------------------------------------------------------------
diff --git a/template/docs/fr/index.html b/template/docs/fr/index.html
index ef14b84..0fa972b 100644
--- a/template/docs/fr/index.html
+++ b/template/docs/fr/index.html
@@ -25,12 +25,6 @@
<div id="sidebar">
<div class="vertical_divider"></div>
- <h1>Sommaire</h1>
- <ul></ul>
- <h1></h1>
- <ul>
- <li><a href="_index.html">Index</a></li>
- </ul>
</div>
<div id="scrollable">
http://git-wip-us.apache.org/repos/asf/incubator-cordova-docs/blob/53fef6b9/template/docs/jp/index.html
----------------------------------------------------------------------
diff --git a/template/docs/jp/index.html b/template/docs/jp/index.html
index fc5899e..cbc116d 100644
--- a/template/docs/jp/index.html
+++ b/template/docs/jp/index.html
@@ -25,12 +25,6 @@
<div id="sidebar">
<div class="vertical_divider"></div>
- <h1>API Reference</h1>
- <ul></ul>
- <h1></h1>
- <ul>
- <li><a href="_index.html">Keyword Index</a></li>
- </ul>
</div>
<div id="scrollable">