loaf 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -8
- data/.ruby-version +1 -0
- data/.travis.yml +23 -2
- data/Appraisals +18 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +16 -1
- data/README.md +69 -52
- data/Rakefile +5 -3
- data/bin/setup +7 -0
- data/gemfiles/rails3.2.gemfile +21 -0
- data/gemfiles/rails4.0.gemfile +22 -0
- data/gemfiles/rails4.1.gemfile +21 -0
- data/gemfiles/rails4.2.gemfile +21 -0
- data/lib/loaf.rb +24 -1
- data/lib/loaf/configuration.rb +15 -22
- data/lib/loaf/controller_extensions.rb +25 -12
- data/lib/loaf/crumb.rb +13 -1
- data/lib/loaf/crumb_formatter.rb +14 -13
- data/lib/loaf/options_validator.rb +10 -2
- data/lib/loaf/translation.rb +15 -8
- data/lib/loaf/version.rb +1 -8
- data/lib/loaf/view_extensions.rb +42 -15
- data/loaf.gemspec +10 -17
- data/spec/integration/configuration_spec.rb +7 -8
- data/spec/integration/crumbs_routing_spec.rb +31 -28
- data/spec/rails_app/app/controllers/application_controller.rb +0 -2
- data/spec/rails_app/app/controllers/posts_controller.rb +13 -2
- data/spec/rails_app/app/views/layouts/_breadcrumbs.html.erb +2 -0
- data/spec/rails_app/app/views/posts/index.html.erb +0 -2
- data/spec/rails_app/app/views/posts/new.html.erb +3 -0
- data/spec/rails_app/app/views/posts/show.html.erb +1 -0
- data/spec/rails_app/config/environments/development.rb +2 -0
- data/spec/rails_app/config/environments/production.rb +2 -0
- data/spec/rails_app/config/environments/test.rb +2 -3
- data/spec/rails_app/config/routes.rb +0 -2
- data/spec/rails_app/{app/mailers → log}/.gitkeep +0 -0
- data/spec/spec_helper.rb +42 -4
- data/spec/support/dummy_view.rb +7 -0
- data/spec/unit/controller_extensions_spec.rb +63 -0
- data/spec/unit/crumb_formatter_spec.rb +38 -0
- data/spec/unit/options_validator_spec.rb +17 -0
- data/spec/unit/translation_spec.rb +22 -0
- data/spec/unit/view_extensions/breadcrumb_spec.rb +24 -0
- data/spec/unit/view_extensions/breadcrumbs_spec.rb +128 -0
- data/spec/unit/view_extensions/has_breadcrumbs_spec.rb +12 -0
- data/tasks/console.rake +10 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/spec.rake +29 -0
- metadata +50 -100
- data/.rvmrc +0 -28
- data/Gemfile.lock +0 -132
- data/spec/integration/nested_crumbs_spec.rb +0 -5
- data/spec/loaf/controller_extensions_spec.rb +0 -55
- data/spec/loaf/crumb_formatter_spec.rb +0 -33
- data/spec/loaf/options_validator_spec.rb +0 -29
- data/spec/loaf/translation_spec.rb +0 -23
- data/spec/loaf/view_extensions_spec.rb +0 -114
- data/spec/loaf_spec.rb +0 -5
- data/spec/rails_app/app/assets/images/rails.png +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +0 -9
- data/spec/rails_app/app/assets/stylesheets/application.css +0 -7
- data/spec/rails_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails_app/app/models/.gitkeep +0 -0
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Loaf::ControllerExtensions do
|
4
|
-
|
5
|
-
class Controller
|
6
|
-
def self.helper_method(*args); end
|
7
|
-
include Loaf::ControllerExtensions
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:name) { stub }
|
11
|
-
let(:url) { stub }
|
12
|
-
let(:options) { stub }
|
13
|
-
|
14
|
-
context 'classes extending controller_extensions' do
|
15
|
-
subject { Controller }
|
16
|
-
specify { should respond_to(:add_breadcrumb) }
|
17
|
-
specify { should respond_to(:breadcrumb) }
|
18
|
-
specify { subject.new.should respond_to(:add_breadcrumb) }
|
19
|
-
specify { subject.new.should respond_to(:breadcrumb) }
|
20
|
-
specify { subject.new.should respond_to(:add_breadcrumbs) }
|
21
|
-
specify { subject.new.should respond_to(:clear_breadcrumbs) }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'class methods' do
|
25
|
-
let(:controller) { Controller }
|
26
|
-
let(:instance) { Class.new(Controller) }
|
27
|
-
|
28
|
-
it 'invokes before_filter' do
|
29
|
-
controller.should_receive(:before_filter)
|
30
|
-
controller.add_breadcrumb('name', 'url_path')
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'delegates to instance' do
|
34
|
-
controller.stub(:before_filter).and_yield instance
|
35
|
-
instance.should_receive(:send).with(:add_breadcrumb, name, url, options)
|
36
|
-
controller.add_breadcrumb(name, url, options)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'instance methods' do
|
41
|
-
let(:controller) { Controller }
|
42
|
-
let(:instance) { Controller.new }
|
43
|
-
|
44
|
-
it 'instantiates breadcrumbs container' do
|
45
|
-
Loaf::Crumb.should_receive(:new).with(name, url)
|
46
|
-
instance.add_breadcrumb(name,url)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'adds breadcrumb to collection' do
|
50
|
-
expect do
|
51
|
-
instance.add_breadcrumb(name, url)
|
52
|
-
end.to change { instance._breadcrumbs.size }.by(1)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end # Loaf::ControllerExtensions
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Loaf::CrumbFormatter do
|
4
|
-
|
5
|
-
let(:formatter) { stub.extend(described_class) }
|
6
|
-
let(:crumb) { Loaf::Crumb.new('some randome name', stub) }
|
7
|
-
|
8
|
-
context '#format_name' do
|
9
|
-
it 'does not capitalize by default' do
|
10
|
-
formatted = formatter.format_name(crumb)
|
11
|
-
formatted.should eql 'some randome name'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'capitalizes crumb name' do
|
15
|
-
formatted = formatter.format_name(crumb, :capitalize => true)
|
16
|
-
formatted.should eql 'Some randome name'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'shortens crumb to provided length' do
|
20
|
-
name = 'very long name that is more that 30 characters long'
|
21
|
-
crumb = Loaf::Crumb.new(name, stub)
|
22
|
-
formatter.should_receive(:truncate).with(name, :length => 30).
|
23
|
-
and_return name[0..30]
|
24
|
-
formatter.format_name(crumb, :crumb_length => 30).should eql name[0..30]
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns name error if breadcrumb name is nil' do
|
28
|
-
crumb = Loaf::Crumb.new('', stub)
|
29
|
-
formatter.format_name(crumb).should eql '[name-error]'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end # Loaf::CrumbFormatter
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Loaf::OptionsValidator do
|
4
|
-
|
5
|
-
let(:klass) { Class.extend Loaf::OptionsValidator }
|
6
|
-
|
7
|
-
describe '.valid?' do
|
8
|
-
context 'when the passed options are valid' do
|
9
|
-
let(:options) do
|
10
|
-
{ :crumb_length => 10 }
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns true' do
|
14
|
-
klass.valid?(options).should be_true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
context 'when the passed optiosn are invalid' do
|
18
|
-
let(:options) do
|
19
|
-
{ :invalid_param => true }
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises an error' do
|
23
|
-
expect do
|
24
|
-
klass.valid? options
|
25
|
-
end.to raise_error(Loaf::InvalidOptions)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end # Loaf::OptionsValidator
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Loaf::Translation do
|
4
|
-
|
5
|
-
before do
|
6
|
-
I18n.backend = I18n::Backend::Simple.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'translates breadcrumb title' do
|
10
|
-
I18n.backend.store_translations 'en', :breadcrumbs => { :home => 'Home'}
|
11
|
-
described_class.breadcrumb_title('breadcrumbs.home').should eql 'Home'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'translates breadcrumb name with default scope' do
|
15
|
-
I18n.backend.store_translations 'en', :breadcrumbs => { :home => 'Home'}
|
16
|
-
described_class.breadcrumb_title('home').should eql 'Home'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'translates breadcrumb name using default option' do
|
20
|
-
described_class.breadcrumb_title('home', :default => 'breadcrumb default name').should eql 'breadcrumb default name'
|
21
|
-
end
|
22
|
-
|
23
|
-
end # Loaf::Translation
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Loaf::ViewExtensions do
|
4
|
-
|
5
|
-
class View < ActionView::Base
|
6
|
-
include Loaf::ViewExtensions
|
7
|
-
attr_accessor_with_default :_breadcrumbs, []
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:name) { 'name' }
|
11
|
-
let(:url) { 'url' }
|
12
|
-
let(:view) { View }
|
13
|
-
let(:instance) { view.new }
|
14
|
-
|
15
|
-
context 'classes extending view_extensions' do
|
16
|
-
subject { View.new }
|
17
|
-
specify { should respond_to(:breadcrumb) }
|
18
|
-
specify { should respond_to(:add_breadcrumb) }
|
19
|
-
specify { should respond_to(:breadcrumbs) }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'adding view breadcrumb' do
|
23
|
-
it 'calls breadcrumbs helper' do
|
24
|
-
instance.should_receive(:_breadcrumbs).and_return []
|
25
|
-
instance.breadcrumb name, url
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'creates crumb instance' do
|
29
|
-
Loaf::Crumb.should_receive(:new).with(name, url)
|
30
|
-
instance.breadcrumb name, url
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should add crumb to breadcrumbs storage' do
|
34
|
-
expect do
|
35
|
-
instance.breadcrumb name, url
|
36
|
-
end.to change { instance._breadcrumbs.size }.by(1)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'breadcrumbs rendering' do
|
41
|
-
|
42
|
-
let(:block) { lambda { |name, url, styles| } }
|
43
|
-
|
44
|
-
before do
|
45
|
-
@crumbs = []
|
46
|
-
@crumbs << Loaf::Crumb.new('home', :home_path)
|
47
|
-
@crumbs << Loaf::Crumb.new('posts', :posts_path)
|
48
|
-
instance.stub(:_breadcrumbs).and_return @crumbs
|
49
|
-
|
50
|
-
@options = {}
|
51
|
-
Loaf.stub_chain(:config, :merge).and_return @options
|
52
|
-
@crumbs.each do |crumb|
|
53
|
-
instance.stub(:format_name).with(crumb, @options).and_return crumb.name
|
54
|
-
instance.stub(:_process_url_for).with(crumb.url).and_return crumb.name
|
55
|
-
end
|
56
|
-
instance.stub(:current_page?).and_return true
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'validates passed options' do
|
60
|
-
instance.should_receive(:valid?)
|
61
|
-
instance.breadcrumbs &block
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'raises error for unkown option' do
|
65
|
-
expect do
|
66
|
-
instance.breadcrumbs :unsupported => true, &block
|
67
|
-
end.to raise_error(Loaf::InvalidOptions)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'calls loaf configuration' do
|
71
|
-
Loaf.should_receive(:config).and_return @options
|
72
|
-
@options.should_receive(:merge).with({:crumb_length => 10}).
|
73
|
-
and_return @options
|
74
|
-
instance.breadcrumbs :crumb_length => 10, &block
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'uses breadcrumbs collection helper' do
|
78
|
-
instance.should_receive(:_breadcrumbs)
|
79
|
-
instance.breadcrumbs &block
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'retrieves crumbs collection' do
|
83
|
-
instance._breadcrumbs.should eql @crumbs
|
84
|
-
instance.breadcrumbs &block
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'formats crumb name' do
|
88
|
-
instance.should_receive(:format_name)
|
89
|
-
instance.breadcrumbs &block
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'checks if crumb url is current' do
|
93
|
-
instance.should_receive(:current_page?)
|
94
|
-
instance.breadcrumbs &block
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'rendering inside block' do
|
98
|
-
it 'returns crumb attributes' do
|
99
|
-
crumb = Loaf::Crumb.new name, url
|
100
|
-
instance.stub(:_breadcrumbs).and_return [crumb]
|
101
|
-
instance.should_receive(:format_name).with(crumb, @options).
|
102
|
-
and_return crumb.name
|
103
|
-
instance.should_receive(:_process_url_for).with(crumb.url).
|
104
|
-
and_return crumb.name
|
105
|
-
|
106
|
-
instance.breadcrumbs do |name, url, styles|
|
107
|
-
name.should eql crumb.name
|
108
|
-
url.should eql crumb.name
|
109
|
-
styles.should be_blank
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end # Loaf::ViewExtensions
|
data/spec/loaf_spec.rb
DELETED
Binary file
|
@@ -1,9 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
-
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
-
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
-
// the compiled file.
|
6
|
-
//
|
7
|
-
//= require jquery
|
8
|
-
//= require jquery_ujs
|
9
|
-
//= require_tree .
|
@@ -1,7 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
-
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
-
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
-
*= require_self
|
6
|
-
*= require_tree .
|
7
|
-
*/
|
File without changes
|