breadcrumbs_on_rails 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ = Changelog
2
+
3
+
4
+ == Release 0.1.1
5
+
6
+ * ADDED: documentation file.
7
+
8
+ * CHANGED: run test against Rails ~> 2.3.0 but ensure compatibility with Rails 2.2.x.
9
+
10
+ * CHANGED: Removed BUILD and STATUS constants. Added Version::ALPHA constant to be used when I need to package prereleases (see RubyGem --prerelease flag).
11
+
12
+
13
+ == Release 0.1.0
14
+
15
+ * Initial version
16
+
data/LICENSE.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Simone Carletti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,19 @@
1
+ CHANGELOG.rdoc
2
+ init.rb
3
+ install.rb
4
+ lib/breadcrumbs_on_rails/breadcrumbs.rb
5
+ lib/breadcrumbs_on_rails/controller_mixin.rb
6
+ lib/breadcrumbs_on_rails/version.rb
7
+ lib/breadcrumbs_on_rails.rb
8
+ LICENSE.rdoc
9
+ Manifest
10
+ rails/init.rb
11
+ Rakefile
12
+ README.rdoc
13
+ tasks/tabs_on_rails_tasks.rake
14
+ test/breadcrumbs_on_rails_test.rb
15
+ test/builder_test.rb
16
+ test/element_test.rb
17
+ test/simple_builder_test.rb
18
+ test/test_helper.rb
19
+ uninstall.rb
data/README.rdoc ADDED
@@ -0,0 +1,67 @@
1
+ = Breadcrumbs On Rails
2
+
3
+ BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing a breadcrumb navigation for a Rails project.
4
+ It provides helpers for creating navigation elements with a flexible interface.
5
+
6
+ Note. This documentation file is a work in progress. Please be patient.
7
+
8
+
9
+ == Requirements
10
+
11
+ * Ruby >= 1.8.6
12
+ * Rails >= 2.2
13
+
14
+
15
+ == Rails Installation
16
+
17
+ === As a Gem
18
+
19
+ This is the preferred way to install BreadcrumbsOnRails and the best way if you want install a stable version.
20
+ The GEM is hosted on {Gemcutter}[http://gemcutter.org/gems/tabs_on_rails].
21
+
22
+ $ gem install breadcrumbs_on_rails --source http://gemcutter.org/
23
+
24
+ With Rails >= 2.2, you can specify the GEM dependency in your environment.rb file so that Rails will automatically check the requirement on startup.
25
+
26
+ Rails::Initializer.run do |config|
27
+
28
+ # other configurations
29
+ # ...
30
+
31
+ config.gem "breadcrumbs_on_rails", :source => "http://gemcutter.org/"
32
+
33
+ end
34
+
35
+ === As a Plugin
36
+
37
+ This is the preferred way if you want to live on the edge and install a development version.
38
+
39
+ $ script/plugin install git://github.com/weppos/breadcrumbs_on_rails.git
40
+
41
+
42
+ == Usage
43
+
44
+ ...
45
+
46
+
47
+ == Documentation
48
+
49
+ The library is still under development and this README file might not be contain the latest changes.
50
+ For the full documentation, development roadmap and more information please visit the {project page}[http://code.simonecarletti.com/wiki/breadonrails].
51
+
52
+
53
+ == Credits
54
+
55
+ Author:: {Simone Carletti}[http://www.simonecarletti.com/] <weppos@weppos.net>
56
+
57
+
58
+ == Resources
59
+
60
+ * {Homepage}[http://code.simonecarletti.com/breadonrails]
61
+ * {GitHub}[http://github.com/weppos/breadcrumbs_on_rails/]
62
+
63
+
64
+ == License
65
+
66
+ Copyright (c) 2009 Simone Carletti, BreadcrumbsOnRails is released under the MIT license.
67
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/lib")
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'echoe'
6
+ require 'breadcrumbs_on_rails'
7
+
8
+
9
+ PKG_NAME = ENV['PKG_NAME'] || BreadcrumbsOnRails::GEM
10
+ PKG_VERSION = ENV['PKG_VERSION'] || BreadcrumbsOnRails::VERSION
11
+ RUBYFORGE_PROJECT = nil
12
+
13
+ if ENV['SNAPSHOT'].to_i == 1
14
+ PKG_VERSION << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
15
+ end
16
+
17
+
18
+ Echoe.new(PKG_NAME, PKG_VERSION) do |p|
19
+ p.author = "Simone Carletti"
20
+ p.email = "weppos@weppos.net"
21
+ p.summary = "A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation."
22
+ p.url = "http://code.simonecarletti.com/breadonrails"
23
+ p.description = <<-EOD
24
+ BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing \
25
+ a breadcrumb navigation for a Rails project. \
26
+ It provides helpers for creating navigation elements with a flexible interface.
27
+ EOD
28
+ p.project = RUBYFORGE_PROJECT
29
+
30
+ p.need_zip = true
31
+
32
+ p.development_dependencies += ["rake ~>0.8.7",
33
+ "echoe ~>3.2.0"]
34
+
35
+ p.rcov_options = ["-Itest -x Rakefile,rcov,json,mocha,rack,actionpack,activesupport"]
36
+ end
37
+
38
+
39
+ begin
40
+ require 'code_statistics'
41
+ desc "Show library's code statistics"
42
+ task :stats do
43
+ CodeStatistics.new(["BreadcrumbsOnRails", "lib"],
44
+ ["Tests", "test"]).to_s
45
+ end
46
+ rescue LoadError
47
+ puts "CodeStatistics (Rails) is not available"
48
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{breadcrumbs_on_rails}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Simone Carletti"]
9
+ s.date = %q{2009-11-27}
10
+ s.description = %q{ BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing a breadcrumb navigation for a Rails project. It provides helpers for creating navigation elements with a flexible interface.
11
+ }
12
+ s.email = %q{weppos@weppos.net}
13
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/breadcrumbs_on_rails/breadcrumbs.rb", "lib/breadcrumbs_on_rails/controller_mixin.rb", "lib/breadcrumbs_on_rails/version.rb", "lib/breadcrumbs_on_rails.rb", "LICENSE.rdoc", "README.rdoc", "tasks/tabs_on_rails_tasks.rake"]
14
+ s.files = ["CHANGELOG.rdoc", "init.rb", "install.rb", "lib/breadcrumbs_on_rails/breadcrumbs.rb", "lib/breadcrumbs_on_rails/controller_mixin.rb", "lib/breadcrumbs_on_rails/version.rb", "lib/breadcrumbs_on_rails.rb", "LICENSE.rdoc", "Manifest", "rails/init.rb", "Rakefile", "README.rdoc", "tasks/tabs_on_rails_tasks.rake", "test/breadcrumbs_on_rails_test.rb", "test/builder_test.rb", "test/element_test.rb", "test/simple_builder_test.rb", "test/test_helper.rb", "uninstall.rb", "breadcrumbs_on_rails.gemspec"]
15
+ s.homepage = %q{http://code.simonecarletti.com/breadonrails}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Breadcrumbs_on_rails", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.}
20
+ s.test_files = ["test/breadcrumbs_on_rails_test.rb", "test/builder_test.rb", "test/element_test.rb", "test/simple_builder_test.rb", "test/test_helper.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
28
+ s.add_development_dependency(%q<echoe>, ["~> 3.2.0"])
29
+ else
30
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
31
+ s.add_dependency(%q<echoe>, ["~> 3.2.0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
35
+ s.add_dependency(%q<echoe>, ["~> 3.2.0"])
36
+ end
37
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,28 @@
1
+ #
2
+ # = Breadcrumbs On Rails
3
+ #
4
+ # A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: BreadcrumbsOnRails
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ require 'breadcrumbs_on_rails/controller_mixin'
18
+ require 'breadcrumbs_on_rails/breadcrumbs'
19
+ require 'breadcrumbs_on_rails/version'
20
+
21
+
22
+ module BreadcrumbsOnRails
23
+
24
+ NAME = 'Breadcrumbs on Rails'
25
+ GEM = 'breadcrumbs_on_rails'
26
+ AUTHORS = ['Simone Carletti <weppos@weppos.net>']
27
+
28
+ end
@@ -0,0 +1,139 @@
1
+ #
2
+ # = Breadcrumbs On Rails
3
+ #
4
+ # A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: BreadcrumbsOnRails
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ module BreadcrumbsOnRails
18
+
19
+ module Breadcrumbs
20
+
21
+ #
22
+ # = Builder
23
+ #
24
+ # The Builder class represents the abstract class for any custom Builder.
25
+ #
26
+ # To create a custom Builder, just extend this class
27
+ # and implement the following abstract methods:
28
+ #
29
+ # render::
30
+ # Renders and returns the collection of navigation elements
31
+ #
32
+ class Builder
33
+
34
+ # Initializes a new Builder with <tt>context</tt>,
35
+ # <tt>element</tt> and <tt>options</tt>.
36
+ #
37
+ # context::
38
+ # The view context, that is current Rails Template instance
39
+ # elements::
40
+ # The collection of Elements
41
+ # options::
42
+ # Hash with optional prefereces or settings to customize the rendering behavior
43
+ #
44
+ def initialize(context, elements, options = {})
45
+ @context = context
46
+ @elements = elements
47
+ @options = options
48
+ end
49
+
50
+ # Renders Elements and returns the Breadcrumb navigation for the view.
51
+ #
52
+ # ==== Raises
53
+ #
54
+ # NotImplemented:: you should implement this method in your custom Builder.
55
+ #
56
+ def render
57
+ raise NotImplementedError
58
+ end
59
+
60
+
61
+ protected
62
+
63
+ def compute_name(element)
64
+ case name = element.name
65
+ when Symbol
66
+ @context.send(name)
67
+ when Proc
68
+ name.call(@context)
69
+ else
70
+ name.to_s
71
+ end
72
+ end
73
+
74
+ def compute_path(element)
75
+ case path = element.path
76
+ when Symbol
77
+ @context.send(path)
78
+ when Proc
79
+ path.call(@context)
80
+ when Hash
81
+ @context.url_for(path)
82
+ else
83
+ path.to_s
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+
90
+
91
+ #
92
+ # = SimpleBuilder
93
+ #
94
+ # The SimpleBuilder is the default breadcrumb builder.
95
+ # It provides basic functionalities to render a breadcrumb navigation.
96
+ #
97
+ # The SimpleBuilder accepts a limited set of options.
98
+ # If you need more flexibility, create a custom Builder and
99
+ # pass the option :builder => BuilderClass to the render_breadcrumbs helper method.
100
+ #
101
+ class SimpleBuilder < Builder
102
+
103
+ def render
104
+ @elements.collect do |element|
105
+ render_element(element)
106
+ end.join(@options[:separator] || " &raquo; ")
107
+ end
108
+
109
+ def render_element(element)
110
+ content = @context.link_to_unless_current(compute_name(element), compute_path(element))
111
+ if @options[:tag]
112
+ @context.content_tag(@options[:tag], content)
113
+ else
114
+ content
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+
121
+ # = Element
122
+ #
123
+ # Represents a navigation element (probably a breadcrumb level)
124
+ # in the breadcrumb collection.
125
+ #
126
+ class Element
127
+
128
+ attr_accessor :name, :path
129
+
130
+ def initialize(name, path)
131
+ self.name = name
132
+ self.path = path
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ end
@@ -0,0 +1,107 @@
1
+ #
2
+ # = Breadcrumbs On Rails
3
+ #
4
+ # A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: BreadcrumbsOnRails
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ module BreadcrumbsOnRails
18
+
19
+ module ControllerMixin
20
+
21
+ def self.included(base)
22
+ base.extend ClassMethods
23
+ base.send :helper, HelperMethods
24
+ base.class_eval do
25
+ include InstanceMethods
26
+ helper HelperMethods
27
+ helper_method :add_breadcrumb, :breadcrumbs
28
+ end
29
+ end
30
+
31
+ module Utils
32
+
33
+ def self.instance_proc(string)
34
+ if string.kind_of?(String)
35
+ proc { |controller| controller.instance_eval(string) }
36
+ else
37
+ string
38
+ end
39
+ end
40
+
41
+ # This is an horrible method with an horrible name.
42
+ #
43
+ # convert_to_set_of_strings(nil, [:foo, :bar])
44
+ # # => nil
45
+ # convert_to_set_of_strings(true, [:foo, :bar])
46
+ # # => ["foo", "bar"]
47
+ # convert_to_set_of_strings(:foo, [:foo, :bar])
48
+ # # => ["foo"]
49
+ # convert_to_set_of_strings([:foo, :bar, :baz], [:foo, :bar])
50
+ # # => ["foo", "bar", "baz"]
51
+ #
52
+ def self.convert_to_set_of_strings(value, keys)
53
+ if value == true
54
+ keys.map(&:to_s).to_set
55
+ elsif value
56
+ Array(value).map(&:to_s).to_set
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ module ClassMethods
63
+
64
+ def add_breadcrumb(name, path, options = {})
65
+ # This isn't really nice here
66
+ if eval = Utils.convert_to_set_of_strings(options.delete(:eval), %w(name path))
67
+ name = Utils.instance_proc(name) if eval.include?("name")
68
+ path = Utils.instance_proc(path) if eval.include?("path")
69
+ end
70
+
71
+ before_filter(options) do |controller|
72
+ controller.send(:add_breadcrumb, name, path)
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ module InstanceMethods
79
+ protected
80
+
81
+ def add_breadcrumb(name, path)
82
+ self.breadcrumbs << Breadcrumbs::Element.new(name, path)
83
+ end
84
+
85
+ def breadcrumbs
86
+ @breadcrumbs ||= []
87
+ end
88
+
89
+ end
90
+
91
+ module HelperMethods
92
+
93
+ def render_breadcrumbs(options = {}, &block)
94
+ builder = (options.delete(:builder) || Breadcrumbs::SimpleBuilder).new(self, breadcrumbs, options)
95
+ content = builder.render
96
+ if block_given?
97
+ concat(capture(content, &block))
98
+ else
99
+ content
100
+ end
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # = Breadcrumbs On Rails
3
+ #
4
+ # A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: BreadcrumbsOnRails
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ # SVN: $Id$
14
+ #++
15
+
16
+
17
+ module BreadcrumbsOnRails
18
+
19
+ module Version
20
+ MAJOR = 0
21
+ MINOR = 1
22
+ PATCH = 1
23
+ ALPHA = nil
24
+
25
+ STRING = [MAJOR, MINOR, PATCH, ALPHA].compact.join('.')
26
+ end
27
+
28
+ VERSION = Version::STRING
29
+
30
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'breadcrumbs_on_rails'
2
+
3
+ ActionController::Base.send :include, BreadcrumbsOnRails::ControllerMixin
4
+
5
+ RAILS_DEFAULT_LOGGER.info("** BreadcrumbsOnRails: initialized properly") if defined?(RAILS_DEFAULT_LOGGER)
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :breadcrumbs_on_rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class BreadcrumbsOnRailsTest < ActiveSupport::TestCase
4
+
5
+ def test_nothing_because_I_have_the_other_test_files
6
+ assert true
7
+ end
8
+
9
+ end
@@ -0,0 +1,112 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class BuilderTest < ActiveSupport::TestCase
5
+
6
+ class TestTemplate
7
+ include ActionView::Helpers::TagHelper
8
+ include ActionView::Helpers::UrlHelper
9
+
10
+ def url_for(params)
11
+ "http://localhost?" + params.to_param
12
+ end
13
+
14
+ protected
15
+
16
+ def method_for_name
17
+ "name from symbol"
18
+ end
19
+
20
+ def proc_for_name
21
+ "name from proc"
22
+ end
23
+
24
+ def method_for_path
25
+ "http://localhost/#symbol"
26
+ end
27
+
28
+ def proc_for_path
29
+ "http://localhost/#proc"
30
+ end
31
+
32
+ end
33
+
34
+
35
+ def setup
36
+ @template = TestTemplate.new
37
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, nil)
38
+ end
39
+
40
+
41
+ def test_initialize_should_require_context_and_elements
42
+ assert_raise(ArgumentError) { BreadcrumbsOnRails::Breadcrumbs::Builder.new }
43
+ assert_raise(ArgumentError) { BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template) }
44
+ assert_nothing_raised { BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, []) }
45
+ end
46
+
47
+ def test_initialize_should_allow_options
48
+ assert_nothing_raised { BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [], {}) }
49
+ end
50
+
51
+ def test_initialize_should_set_context
52
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
53
+ assert_equal(@template, @builder.instance_variable_get(:'@context'))
54
+ end
55
+
56
+ def test_initialize_should_set_elements
57
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [1, 2])
58
+ assert_equal([1, 2], @builder.instance_variable_get(:'@elements'))
59
+ end
60
+
61
+
62
+ def test_compute_name_with_symbol
63
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
64
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new(:method_for_name, nil)
65
+
66
+ assert_equal("name from symbol", @builder.send(:compute_name, @element))
67
+ end
68
+
69
+ def test_compute_name_with_proc
70
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
71
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new(proc { |template| template.send(:proc_for_name) }, nil)
72
+
73
+ assert_equal("name from proc", @builder.send(:compute_name, @element))
74
+ end
75
+
76
+ def test_compute_name_with_string
77
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
78
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new("name from string", nil)
79
+
80
+ assert_equal("name from string", @builder.send(:compute_name, @element))
81
+ end
82
+
83
+
84
+ def test_compute_path_with_symbol
85
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
86
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, :method_for_path)
87
+
88
+ assert_equal("http://localhost/#symbol", @builder.send(:compute_path, @element))
89
+ end
90
+
91
+ def test_compute_path_with_proc
92
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
93
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, proc { |template| template.send(:proc_for_path) })
94
+
95
+ assert_equal("http://localhost/#proc", @builder.send(:compute_path, @element))
96
+ end
97
+
98
+ def test_compute_path_with_hash
99
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
100
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, { :foo => "bar" })
101
+
102
+ assert_equal("http://localhost?foo=bar", @builder.send(:compute_path, @element))
103
+ end
104
+
105
+ def test_compute_path_with_string
106
+ @builder = BreadcrumbsOnRails::Breadcrumbs::Builder.new(@template, [])
107
+ @element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, "http://localhost/#string")
108
+
109
+ assert_equal("http://localhost/#string", @builder.send(:compute_path, @element))
110
+ end
111
+
112
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class ElementTest < ActiveSupport::TestCase
4
+
5
+ def test_initialize_should_require_name_and_path
6
+ assert_raise(ArgumentError) { BreadcrumbsOnRails::Breadcrumbs::Element.new }
7
+ assert_raise(ArgumentError) { BreadcrumbsOnRails::Breadcrumbs::Element.new(nil) }
8
+ assert_nothing_raised { BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, nil) }
9
+ end
10
+
11
+ def test_initialize_should_set_name
12
+ element = BreadcrumbsOnRails::Breadcrumbs::Element.new(:fooname, nil)
13
+ assert_equal :fooname, element.name
14
+ end
15
+
16
+ def test_initialize_should_set_path
17
+ element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, :foopath)
18
+ assert_equal :foopath, element.path
19
+ end
20
+
21
+
22
+ def test_name
23
+ element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, nil)
24
+ element.name = :the_name
25
+ assert_equal :the_name, element.name
26
+ end
27
+
28
+ def test_path
29
+ element = BreadcrumbsOnRails::Breadcrumbs::Element.new(nil, nil)
30
+ element.path = { :controller => "index", :action => "index" }
31
+ assert_equal({ :controller => "index", :action => "index" }, element.path)
32
+ end
33
+
34
+ end
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class SimpleBuilderTest < ActionView::TestCase
5
+
6
+ class TestTemplate
7
+ include ActionView::Helpers::TagHelper
8
+ include ActionView::Helpers::UrlHelper
9
+ end
10
+
11
+
12
+ def setup
13
+ @template = TestTemplate.new
14
+ end
15
+
16
+ def test_render_should_be_implemented
17
+ assert_nothing_raised { simplebuilder(@template, []).render }
18
+ end
19
+
20
+
21
+ def test_render_with_0_elements
22
+ assert_equal("", simplebuilder(@template, []).render)
23
+ end
24
+
25
+ def test_render_with_0_elements_and_separator
26
+ assert_equal("", simplebuilder(@template, [], :separator => "-").render)
27
+ end
28
+
29
+
30
+ def test_render_with_1_element
31
+ @template.expects(:current_page?).times(1).returns(false)
32
+ assert_dom_equal("<a href=\"/element/1\">Element 1</a>",
33
+ simplebuilder(@template, generate_elements(1)).render)
34
+ end
35
+
36
+ def test_render_with_1_element_and_separator
37
+ @template.expects(:current_page?).times(1).returns(false)
38
+ assert_dom_equal("<a href=\"/element/1\">Element 1</a>",
39
+ simplebuilder(@template, generate_elements(1), :separator => "-").render)
40
+ end
41
+
42
+
43
+ def test_render
44
+ @template.expects(:current_page?).times(2).returns(false)
45
+ assert_dom_equal("<a href=\"/element/1\">Element 1</a> &raquo; <a href=\"/element/2\">Element 2</a>",
46
+ simplebuilder(@template, generate_elements(2)).render)
47
+ end
48
+
49
+ def test_render_with_separator
50
+ @template.expects(:current_page?).times(2).returns(false)
51
+ assert_dom_equal("<a href=\"/element/1\">Element 1</a> - <a href=\"/element/2\">Element 2</a>",
52
+ simplebuilder(@template, generate_elements(2), :separator => " - ").render)
53
+ end
54
+
55
+ def test_render_with_current_page
56
+ @template.expects(:current_page?).times(2).returns(false, true)
57
+ assert_dom_equal("<a href=\"/element/1\">Element 1</a> &raquo; Element 2",
58
+ simplebuilder(@template, generate_elements(2)).render)
59
+ end
60
+
61
+
62
+ protected
63
+
64
+ def simplebuilder(*args)
65
+ BreadcrumbsOnRails::Breadcrumbs::SimpleBuilder.new(*args)
66
+ end
67
+
68
+ def generate_elements(number)
69
+ (1..number).collect do |index|
70
+ BreadcrumbsOnRails::Breadcrumbs::Element.new("Element #{index}", "/element/#{index}")
71
+ end
72
+ end
73
+
74
+
75
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ gem 'rails', '~>2.3.0'
3
+ gem 'mocha', '~>0.9.7'
4
+
5
+ # Remember! Due to some Mocha internal changes,
6
+ # Rails 2.2.x requires Mocha 0.9.5 and
7
+ # Rails 2.3.x requires Mocha 0.9.7
8
+ # gem 'rails', '2.2.2'
9
+ # gem 'mocha', '0.9.5'
10
+
11
+ require 'test/unit'
12
+ require 'active_support'
13
+ require 'action_controller'
14
+ require 'action_view/test_case'
15
+
16
+ $:.unshift File.dirname(__FILE__) + '/../lib'
17
+ require File.dirname(__FILE__) + '/../init.rb'
18
+
19
+ RAILS_ROOT = '.' unless defined? RAILS_ROOT
20
+ RAILS_ENV = 'test' unless defined? RAILS_ENV
21
+
22
+ ActionController::Base.logger = nil
23
+ ActionController::Routing::Routes.reload rescue nil
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: breadcrumbs_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Simone Carletti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-27 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.7
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
34
+ version:
35
+ description: " BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing a breadcrumb navigation for a Rails project. It provides helpers for creating navigation elements with a flexible interface.\n"
36
+ email: weppos@weppos.net
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - CHANGELOG.rdoc
43
+ - lib/breadcrumbs_on_rails/breadcrumbs.rb
44
+ - lib/breadcrumbs_on_rails/controller_mixin.rb
45
+ - lib/breadcrumbs_on_rails/version.rb
46
+ - lib/breadcrumbs_on_rails.rb
47
+ - LICENSE.rdoc
48
+ - README.rdoc
49
+ - tasks/tabs_on_rails_tasks.rake
50
+ files:
51
+ - CHANGELOG.rdoc
52
+ - init.rb
53
+ - install.rb
54
+ - lib/breadcrumbs_on_rails/breadcrumbs.rb
55
+ - lib/breadcrumbs_on_rails/controller_mixin.rb
56
+ - lib/breadcrumbs_on_rails/version.rb
57
+ - lib/breadcrumbs_on_rails.rb
58
+ - LICENSE.rdoc
59
+ - Manifest
60
+ - rails/init.rb
61
+ - Rakefile
62
+ - README.rdoc
63
+ - tasks/tabs_on_rails_tasks.rake
64
+ - test/breadcrumbs_on_rails_test.rb
65
+ - test/builder_test.rb
66
+ - test/element_test.rb
67
+ - test/simple_builder_test.rb
68
+ - test/test_helper.rb
69
+ - uninstall.rb
70
+ - breadcrumbs_on_rails.gemspec
71
+ has_rdoc: true
72
+ homepage: http://code.simonecarletti.com/breadonrails
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --line-numbers
78
+ - --inline-source
79
+ - --title
80
+ - Breadcrumbs_on_rails
81
+ - --main
82
+ - README.rdoc
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "1.2"
96
+ version:
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.5
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.
104
+ test_files:
105
+ - test/breadcrumbs_on_rails_test.rb
106
+ - test/builder_test.rb
107
+ - test/element_test.rb
108
+ - test/simple_builder_test.rb
109
+ - test/test_helper.rb