radiant-navigation_tags-extension 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ [Tuesday; October 9, 2007]
2
+
3
+ Added 3 optional parameters; "root", "include_root" and "depth"
4
+ - By default, root is still "/", otherwise you can use this to build sub-nav's
5
+ - You can still include the root_page by setting include_root to true
6
+ - Default depth is 1, which means no sub-ul's
7
+
8
+ Thanks for the patch: Benny Degezelle
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2007 Ryan Heneise (http://www.artofmission.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice, and every other copyright notice found in this
11
+ software, and all the attributions in every file, and this permission notice
12
+ shall be included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+
data/README ADDED
@@ -0,0 +1,44 @@
1
+ = Navigation Tags
2
+
3
+ Provides hierarchical tree navigation based on Radiant's site structure. Outputs navigation in the form of a -very flexible and CSS'able- unordered list. Also provides r:if_self and r:if_ancestor_or_self
4
+
5
+ == Usage
6
+
7
+ <r:nav [root="/"] [include_root="true"] [depth="2"] [expand_all="true"] [ids_for_lis="true"] />
8
+
9
+ Given this directory tree:
10
+
11
+ * Home
12
+ ** About
13
+ *** Contact us
14
+ ** Blog
15
+ *** First Article
16
+ *** Second Article
17
+ ** Catalog
18
+
19
+ <r:nav /> would output a navigation list like:
20
+
21
+ <ul>
22
+ <li class="parent_of_current has_children"><a href="/about/">About</a>
23
+ <ul>
24
+ <li class="current"><a href="/about/contact">Contact Us</a></li>
25
+ </ul>
26
+ </li>
27
+ <li class="has_children"><a href="/blog/">Blog</a></li>
28
+ <li class="has_children"><a href="/catalogue">Catalogue</a></li>
29
+ </ul>
30
+
31
+ == Available tag attributes:
32
+
33
+ * ids_for_lis: defaults to false, enable this to give each li an id (it's slug)
34
+ * root: defaults to "/", which page to start building the navigation from
35
+ * include_root: defaults to false, set to true to include the root page (i.e. Home)
36
+ * depth: defaults to 2, which will print out the first two levels of pages.
37
+ * expand_all: defaults to false, enable this to have all li's create sub-ul's of their children, i.o. only the currently active li
38
+ * id, class, monkeyballs, ... will be used as html attributes for the ul
39
+
40
+ = CREDITS
41
+
42
+ * Ryan Heneise
43
+ * Marty Haught
44
+ * Benny Degezelle
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the navigation_tags extension.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the navigation_tags extension.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'NavigationTagsExtension'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+ # Load any custom rakefiles for extension
25
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
26
+
27
+ begin
28
+ require 'jeweler'
29
+ Jeweler::Tasks.new do |gem|
30
+ gem.name = "radiant-navigation_tags-extension"
31
+ gem.summary = %Q{Navigation tags extension for Radiant CMS}
32
+ gem.description = %Q{Adds r:nav, a versatile navigation building tag to Radiant CMS}
33
+ gem.email = "benny@gorilla-webdesign.be"
34
+ gem.homepage = "https://github.com/jomz/navigation_tags"
35
+ gem.authors = ["Benny Degezelle"]
36
+ gem.add_dependency 'radiant', ">=0.9.1"
37
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
38
+ end
39
+ rescue LoadError
40
+ puts "Jeweler (or a dependency) not available. This is only required if you plan to package copy_move as a gem."
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,135 @@
1
+ module NavigationTags
2
+ include Radiant::Taggable
3
+ include ActionView::Helpers::TagHelper
4
+
5
+ class NavTagError < StandardError; end
6
+
7
+ desc %{Render a navigation menu. Walks down the directory tree, expanding the tree up to the current page.
8
+
9
+ *Usage:*
10
+ <pre><code><r:nav [id="subnav"] [root=\"/products\"] [append_urls=\"/,/about-us/contact\"] [depth=\"2\"] [expand_all=\"true\"]/></code></pre>
11
+ *Attributes:*
12
+
13
+ root: defaults to "/", where to start building the navigation from, you can i.e. use "/products" to build a subnav
14
+ append_urls: urls of pages to add to the end of the navigation ul seperated by a comma
15
+ prepend_urls: urls of pages to add to the beginning of the navigation ul seperated by a comma
16
+ ids_for_lis: defaults to false, enable this to give each li an id (it's slug prefixed with nav_)
17
+ ids_for_links: defaults to false, enable this to give each link an id (it's slug prefixed with nav_)
18
+
19
+ depth: defaults to 1, which means no sub-ul's, set to 2 or more for a nested list
20
+ expand_all: defaults to false, enable this to have all li's create sub-ul's of their children, i.o. only the currently active li
21
+ id, class,..: go as html attributes of the outer ul
22
+ }
23
+
24
+ tag "nav" do |tag|
25
+ if tag.double?
26
+ root = Page.find_by_path(tag.expand)
27
+ elsif defined?(Globalize2Extension) && Globalize2Extension.locales.size > 1
28
+ root = Page.find_by_path(root_url = tag.attr.delete('root') || "/#{I18n.locale}")
29
+ else
30
+ root = Page.find_by_path(root_url = tag.attr.delete('root') || "/")
31
+ end
32
+
33
+ raise NavTagError, "No page found at \"#{root_url}\" to build navigation from." if root.class_name.eql?('FileNotFoundPage')
34
+
35
+ depth = tag.attr.delete('depth') || 1
36
+ ['ids_for_lis', 'ids_for_links', 'expand_all', 'first_set', 'prepend_urls', 'append_urls'].each do |prop|
37
+ eval "@#{prop} = tag.attr.delete('#{prop}') || false"
38
+ end
39
+
40
+ lis = []
41
+
42
+ if @prepend_urls
43
+ @prepend_urls.split(",").compact.each do |url|
44
+ page = Page.find_by_path(url)
45
+ if page.class_name != "FileNotFoundPage"
46
+ lis << li_for_current_page_vs_navigation_item(tag.locals.page, page)
47
+ end
48
+ end
49
+ end
50
+
51
+ for child in root.children
52
+ lis << tag.render('sub-nav', {:page => child, :depth => depth.to_i - 1, :first_set => @first_set })
53
+ end
54
+
55
+ if @append_urls
56
+ @append_urls.split(",").compact.each do |url|
57
+ page = Page.find_by_path(url)
58
+ if page.class_name != "FileNotFoundPage"
59
+ lis << li_for_current_page_vs_navigation_item(tag.locals.page, page)
60
+ end
61
+ end
62
+ end
63
+
64
+ if tag.attr
65
+ html_options = tag.attr.stringify_keys
66
+ tag_options = tag_options(html_options)
67
+ else
68
+ tag_options = nil
69
+ end
70
+
71
+ %{<ul#{tag_options}>
72
+ #{lis.join}
73
+ </ul>}
74
+
75
+ end
76
+
77
+ tag "sub-nav" do |tag|
78
+ current_page = tag.locals.page
79
+ child_page = tag.attr[:page]
80
+ @depth ||= tag.attr.delete(:depth)
81
+ @first_set ||= tag.attr.delete(:first_set)
82
+ return if @depth < 0 or child_page.virtual? or !child_page.published? or child_page.class_name.eql? "FileNotFoundPage" or child_page.part("no-map")
83
+
84
+ r = %{<li#{li_attrs_for_current_page_vs_navigation_item(current_page, child_page)}>
85
+ #{link_for_page(child_page)}\n}
86
+ # mind the open li
87
+ rr = ""
88
+ if child_page.children.size > 0 and
89
+ @depth.to_i > 0 and
90
+ child_page.class_name != 'ArchivePage' and
91
+ (@expand_all || current_page.url.starts_with?(child_page.url) )
92
+ @first_set = false
93
+ child_page.children.each do |child|
94
+ rr << tag.render('sub-nav', :page => child, :depth => @depth.to_i - 1, :first_set => @first_set ) unless child.part("no-map") || !child.published?
95
+ end
96
+
97
+ r << "<ul>\n" + rr + "</ul>\n" unless rr.empty?
98
+ end
99
+ r << "</li>\n"
100
+ end
101
+
102
+ def li_attrs_for_current_page_vs_navigation_item current_page, child_page
103
+ classes = [
104
+ ("current" if current_page == child_page),
105
+ ("has_children" if child_page.children.size > 0),
106
+ ("parent_of_current" if current_page.url.starts_with?(child_page.url) and current_page != child_page)
107
+ ]
108
+ if !@first_set
109
+ classes << "first"
110
+ @first_set = true
111
+ end
112
+
113
+ result = ""
114
+ if classes.any?
115
+ result = " class=\"#{classes.compact.join(" ")}\""
116
+ end
117
+ if @ids_for_lis
118
+ result << " id=\"nav_" + child_page.slug + "\""
119
+ end
120
+ result
121
+ end
122
+
123
+ def li_for_current_page_vs_navigation_item current_page, child_page
124
+ "<li#{li_attrs_for_current_page_vs_navigation_item(current_page, child_page)}>#{link_for_page(child_page)}</li>"
125
+ end
126
+
127
+ def link_for_page page
128
+ if @ids_for_links
129
+ "<a href=\"#{page.url}\" id=\"#{("link_" + (page.slug == "/" ? 'home' : page.slug))}\">#{escape_once(page.breadcrumb)}</a>"
130
+ else
131
+ "<a href=\"#{page.url}\">#{escape_once(page.breadcrumb)}</a>"
132
+ end
133
+ end
134
+
135
+ end
@@ -0,0 +1,17 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :navigation_tags do
4
+
5
+ desc "Runs the migration of the Navigation Tags extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ NavigationTagsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ NavigationTagsExtension.migrator.migrate
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ class NavigationTagsExtension < Radiant::Extension
2
+ version "2.1"
3
+ description "Makes building navigations much easier."
4
+ url "https://github.com/jomz/navigation_tags"
5
+
6
+ def activate
7
+ Page.send :include, NavigationTags
8
+ end
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-navigation_tags-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
11
+ platform: ruby
12
+ authors:
13
+ - Benny Degezelle
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-29 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: radiant
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 57
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 1
34
+ version: 0.9.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Adds r:nav, a versatile navigation building tag to Radiant CMS
38
+ email: benny@gorilla-webdesign.be
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README
46
+ files:
47
+ - CHANGELOG
48
+ - LICENSE
49
+ - README
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/navigation_tags.rb
53
+ - lib/tasks/navigation_tags_extension_tasks.rake
54
+ - navigation_tags_extension.rb
55
+ has_rdoc: true
56
+ homepage: https://github.com/jomz/navigation_tags
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Navigation tags extension for Radiant CMS
89
+ test_files: []
90
+