radiant-navigation-extension 2.0.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,48 @@
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
+ = NOTES
41
+
42
+ * This does not behave like the original extension and has been made to simply support calling the tag
43
+
44
+ = CREDITS
45
+
46
+ * Ryan Heneise
47
+ * Marty Haught
48
+ * Benny Degezelle
data/Rakefile ADDED
@@ -0,0 +1,137 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "radiant-navigation-extension"
5
+ gem.summary = %Q{Navigation Generation for Radiant CMS}
6
+ gem.description = %Q{Navigation provides a way to generate navigation (with useful classes)}
7
+ gem.email = "dk@dirkkelly.com"
8
+ gem.homepage = "http://github.com/dirkkelly/radiant-navigation-extension"
9
+ gem.authors = ["Phil Schilter", "Dirk Kelly"]
10
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
11
+ end
12
+ Jeweler::GemcutterTasks.new
13
+ rescue LoadError
14
+ puts "Jeweler (or a dependency) not available. This is only required if you plan to package navigation as a gem."
15
+ end
16
+
17
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
18
+ # Check to see if the rspec plugin is installed first and require
19
+ # it if it is. If not, use the gem version.
20
+
21
+ # Determine where the RSpec plugin is by loading the boot
22
+ unless defined? RADIANT_ROOT
23
+ ENV["RAILS_ENV"] = "test"
24
+ case
25
+ when ENV["RADIANT_ENV_FILE"]
26
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
27
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
28
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
29
+ else
30
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
31
+ end
32
+ end
33
+
34
+ require 'rake'
35
+ require 'rake/rdoctask'
36
+ require 'rake/testtask'
37
+
38
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
39
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
40
+ require 'spec/rake/spectask'
41
+ require 'cucumber'
42
+ require 'cucumber/rake/task'
43
+
44
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
45
+ Object.send(:remove_const, :RADIANT_ROOT)
46
+
47
+ extension_root = File.expand_path(File.dirname(__FILE__))
48
+
49
+ task :default => :spec
50
+ task :stats => "spec:statsetup"
51
+
52
+ desc "Run all specs in spec directory"
53
+ Spec::Rake::SpecTask.new(:spec) do |t|
54
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
55
+ t.spec_files = FileList['spec/**/*_spec.rb']
56
+ end
57
+
58
+ task :features => 'spec:integration'
59
+
60
+ namespace :spec do
61
+ desc "Run all specs in spec directory with RCov"
62
+ Spec::Rake::SpecTask.new(:rcov) do |t|
63
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
64
+ t.spec_files = FileList['spec/**/*_spec.rb']
65
+ t.rcov = true
66
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
67
+ end
68
+
69
+ desc "Print Specdoc for all specs"
70
+ Spec::Rake::SpecTask.new(:doc) do |t|
71
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
72
+ t.spec_files = FileList['spec/**/*_spec.rb']
73
+ end
74
+
75
+ [:models, :controllers, :views, :helpers].each do |sub|
76
+ desc "Run the specs under spec/#{sub}"
77
+ Spec::Rake::SpecTask.new(sub) do |t|
78
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
79
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
80
+ end
81
+ end
82
+
83
+ desc "Run the Cucumber features"
84
+ Cucumber::Rake::Task.new(:integration) do |t|
85
+ t.fork = true
86
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
87
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
88
+ t.profile = "default"
89
+ end
90
+
91
+ # Setup specs for stats
92
+ task :statsetup do
93
+ require 'code_statistics'
94
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
95
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
96
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
97
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
98
+ ::CodeStatistics::TEST_TYPES << "Model specs"
99
+ ::CodeStatistics::TEST_TYPES << "View specs"
100
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
101
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
102
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
103
+ end
104
+
105
+ namespace :db do
106
+ namespace :fixtures do
107
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
108
+ task :load => :environment do
109
+ require 'active_record/fixtures'
110
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
111
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
112
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ desc 'Generate documentation for the navigation extension.'
120
+ Rake::RDocTask.new(:rdoc) do |rdoc|
121
+ rdoc.rdoc_dir = 'rdoc'
122
+ rdoc.title = 'NavigationExtension'
123
+ rdoc.options << '--line-numbers' << '--inline-source'
124
+ rdoc.rdoc_files.include('README')
125
+ rdoc.rdoc_files.include('lib/**/*.rb')
126
+ end
127
+
128
+ # For extensions that are in transition
129
+ desc 'Test the navigation extension.'
130
+ Rake::TestTask.new(:test) do |t|
131
+ t.libs << 'lib'
132
+ t.pattern = 'test/**/*_test.rb'
133
+ t.verbose = true
134
+ end
135
+
136
+ # Load any custom rakefiles for extension
137
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.1
@@ -0,0 +1,116 @@
1
+ module Navigation
2
+ module Tags
3
+ module Core
4
+ include Radiant::Taggable
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ class NavTagError < StandardError; end
8
+
9
+ desc %{
10
+ Render a navigation menu. Walks down the directory tree, expanding the tree up to the current page.
11
+
12
+ *Usage:*
13
+ <pre><code><r:nav [id="subnav"] [root="/products"] [include_root="true"] [depth="2"] [expand_all="true"]
14
+ [only="^/(articles|notices)"] [except="\.(css|js|xml)/*$"] /></code></pre>
15
+ *Attributes:*
16
+
17
+ * @root@ defaults to "root page", where to start building the navigation from, you can i.e. use "sexy-dresses" to build a nav under sexy dresses
18
+ * @include_root@ defaults to false, set to true to include the root page (i.e. Home)
19
+ * @ids_for_lis@ defaults to false, enable this to give each li an id (it's slug prefixed with nav_)
20
+ * @ids_for_links@ defaults to false, enable this to give each link an id (it's slug prefixed with nav_)
21
+
22
+ * @depth@ defaults to 1, which means no sub-ul's, set to 2 or more for a nested list
23
+ * @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
24
+
25
+ * @only@ a string or regular expresssion. only pages whose urls match this are included
26
+ * @except@ a string or regular expresssion. pages whose urls match this are not shown. except will override only. use to eliminate non-content file-types
27
+
28
+ * @id@, @class@,..: go as html attributes of the outer ul
29
+ }
30
+
31
+ tag "nav" do |tag|
32
+ root_url = tag.attr.delete('root').to_s || "/"
33
+ root = Page.find_by_url(root_url)
34
+ depth = tag.attr.delete('depth').to_i || 1
35
+ tree = ""
36
+
37
+ raise NavTagError, "No page found at \"#{root_url}\" to build navigation from." if root.class_name.eql?('FileNotFoundPage')
38
+
39
+ if tag.attr['include_root']
40
+ css_class = [("current" if tag.locals.page == root), "first"].compact
41
+ first_set = true
42
+
43
+ tree << %{<li class="#{css_class.join(' ') unless css_class.empty?}" id="#{(root.slug == '/' ? 'home' : root.slug) if tag.attr['ids_for_lis']}">}
44
+ tree << %{<a href="#{root.url}" id="link_#{(child_page.slug == '/' ? 'home' : root.slug) if tag.attr['ids_for_links']}">}
45
+ tree << %{#{root.breadcrumb}}
46
+ tree << %{</a></li>}
47
+ end
48
+
49
+ for child in root.children
50
+ unless Helpers.not_allowed?(tag,child)
51
+ depth -= 1
52
+ tree << Helpers.sub_nav(tag, child, depth, first_set)
53
+ end
54
+ end
55
+
56
+ if tag.attr
57
+ html_options = tag.attr.stringify_keys
58
+ tag_options = tag_options(html_options)
59
+ else
60
+ tag_options = nil
61
+ end
62
+
63
+ %{<ul#{tag_options}>
64
+ #{tree}
65
+ </ul>}
66
+
67
+ end
68
+
69
+ # Inspired by this thread:
70
+ # http://www.mail-archive.com/radiant@lists.radiantcms.org/msg03234.html
71
+ # Author: Marty Haught
72
+ desc %{
73
+ Renders the contained element if the current item is an ancestor of the current page or if it is the page itself.
74
+ }
75
+ tag "if_ancestor_or_self" do |tag|
76
+ if tag.globals.actual_page.url.starts_with?(tag.locals.page.url)
77
+ tag.expand
78
+ end
79
+ end
80
+
81
+ desc %{
82
+ Renders the contained element if the current item is also the current page.
83
+ }
84
+ tag "if_self" do |tag|
85
+ if tag.locals.page == tag.globals.page
86
+ tag.expand
87
+ end
88
+ end
89
+
90
+ desc %{
91
+ Renders the contained elements only if the current contextual page has children.
92
+
93
+ *Usage:*
94
+ <pre><code><r:if_children>...</r:if_children></code></pre>
95
+ }
96
+ tag "if_children" do |tag|
97
+ if tag.locals.page.children.present?
98
+ tag.expand
99
+ end
100
+ end
101
+
102
+ desc %{
103
+ Renders the contained elements unless the current contextual page has children.
104
+
105
+ *Usage:*
106
+ <pre><code><r:if_children>...</r:if_children></code></pre>
107
+ }
108
+ tag "unless_children" do |tag|
109
+ unless tag.locals.page.children.blank?
110
+ tag.expand
111
+ end
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,46 @@
1
+ module Navigation
2
+ module Tags
3
+ class Helpers
4
+ class << self
5
+
6
+ def not_allowed?(tag,child_page)
7
+ (tag.attr['only'] and !child_page.url.match(tag.attr['only'])) or
8
+ (tag.attr['except'] and child_page.url.match(tag.attr['except'])) or
9
+ child_page.part("no-map") or child_page.virtual? or !child_page.published? or child_page.class_name.eql? "FileNotFoundPage"
10
+ end
11
+
12
+ def sub_nav(tag, child_page, depth, first_set = false)
13
+ current_page = tag.locals.page
14
+
15
+ css_class = []
16
+ css_class << 'first' unless first_set
17
+ css_class << "current" if current_page == child_page
18
+ css_class << "has_children" if child_page.children.present?
19
+ css_class << "parent_of_current" if current_page.url.starts_with?(child_page.url) and current_page != child_page
20
+ css_class.compact!
21
+
22
+ r = %{<li class="#{css_class.join(' ') unless css_class.empty?}" id="nav_#{child_page.slug if tag.attr['ids_for_lis']}">}
23
+ r << %{<a href="#{child_page.url}" id="link_#{(child_page.slug == '/' ? 'home' : child_page.slug) if tag.attr['ids_for_links']}">}
24
+ r << %{#{child_page.breadcrumb}}
25
+ r << %{</a>}
26
+
27
+ allowed_children = child_page.children.delete_if{ |c| not_allowed?(tag,c) }
28
+
29
+ if tag.attr['expand_all'] or current_page.url.starts_with?(child_page.url)
30
+ if allowed_children.present? and depth.present? and child_page.class_name != 'ArchivePage'
31
+ r << %{<ul>}
32
+ child_page.children.each do |child|
33
+ depth -= 1
34
+ r << sub_nav(tag,child,depth,first_set)
35
+ end
36
+ r << %{</ul>}
37
+ end
38
+ end
39
+
40
+ r << %{</li>}
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1 @@
1
+ # Nothing to see here
@@ -0,0 +1,13 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency 'application'
3
+
4
+ class NavigationExtension < Radiant::Extension
5
+ version YAML::load_file(File.join(File.dirname(__FILE__), 'VERSION'))
6
+ description "Makes building navigations much easier."
7
+ url "http://github.com/dirkkelly/radiant-navigation-extension"
8
+
9
+ def activate
10
+ Page.send :include, Navigation::Tags::Core
11
+ end
12
+
13
+ end
@@ -0,0 +1,46 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{radiant-navigation-extension}
8
+ s.version = "2.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Phil Schilter", "Dirk Kelly"]
12
+ s.date = %q{2010-11-28}
13
+ s.description = %q{Navigation provides a way to generate navigation (with useful classes)}
14
+ s.email = %q{dk@dirkkelly.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ "CHANGELOG",
21
+ "LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/navigation/tags/core.rb",
26
+ "lib/navigation/tags/helpers.rb",
27
+ "lib/radiant-navigation-extension.rb",
28
+ "navigation_extension.rb",
29
+ "radiant-navigation-extension.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/dirkkelly/radiant-navigation-extension}
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.7}
34
+ s.summary = %q{Navigation Generation for Radiant CMS}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ else
42
+ end
43
+ else
44
+ end
45
+ end
46
+
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-navigation-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 1
10
+ version: 2.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Phil Schilter
14
+ - Dirk Kelly
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-11-28 00:00:00 +08:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Navigation provides a way to generate navigation (with useful classes)
24
+ email: dk@dirkkelly.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - LICENSE
31
+ - README
32
+ files:
33
+ - CHANGELOG
34
+ - LICENSE
35
+ - README
36
+ - Rakefile
37
+ - VERSION
38
+ - lib/navigation/tags/core.rb
39
+ - lib/navigation/tags/helpers.rb
40
+ - lib/radiant-navigation-extension.rb
41
+ - navigation_extension.rb
42
+ - radiant-navigation-extension.gemspec
43
+ has_rdoc: true
44
+ homepage: http://github.com/dirkkelly/radiant-navigation-extension
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.7
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Navigation Generation for Radiant CMS
77
+ test_files: []
78
+