loaf 0.6.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +67 -12
- data/LICENSE.txt +1 -1
- data/README.md +82 -39
- data/lib/loaf.rb +1 -0
- data/lib/loaf/configuration.rb +0 -12
- data/lib/loaf/controller_extensions.rb +9 -1
- data/lib/loaf/errors.rb +1 -1
- data/lib/loaf/translation.rb +12 -4
- data/lib/loaf/version.rb +3 -1
- data/lib/loaf/view_extensions.rb +16 -8
- metadata +19 -161
- data/.document +0 -5
- data/.gitignore +0 -23
- data/.rspec +0 -2
- data/.travis.yml +0 -48
- data/Appraisals +0 -36
- data/Gemfile +0 -19
- data/Gemfile.lock +0 -185
- data/Rakefile +0 -10
- data/assets/loaf_logo.png +0 -0
- data/bin/appraisal +0 -16
- data/bin/rake +0 -16
- data/bin/setup +0 -7
- data/gemfiles/rails3.2.gemfile +0 -24
- data/gemfiles/rails4.0.gemfile +0 -24
- data/gemfiles/rails4.1.gemfile +0 -23
- data/gemfiles/rails4.2.gemfile +0 -23
- data/gemfiles/rails5.0.gemfile +0 -22
- data/gemfiles/rails5.1.gemfile +0 -22
- data/lib/loaf/crumb_formatter.rb +0 -24
- data/loaf.gemspec +0 -28
- data/spec/integration/breadcrumb_trail_spec.rb +0 -60
- data/spec/integration/configuration_spec.rb +0 -12
- data/spec/rails_app/Rakefile +0 -8
- data/spec/rails_app/app/controllers/application_controller.rb +0 -5
- data/spec/rails_app/app/controllers/comments_controller.rb +0 -17
- data/spec/rails_app/app/controllers/home_controller.rb +0 -4
- data/spec/rails_app/app/controllers/posts_controller.rb +0 -20
- data/spec/rails_app/app/views/comments/index.html.erb +0 -1
- data/spec/rails_app/app/views/home/index.html.erb +0 -1
- data/spec/rails_app/app/views/layouts/_breadcrumbs.html.erb +0 -12
- data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails_app/app/views/posts/index.html.erb +0 -1
- data/spec/rails_app/app/views/posts/new.html.erb +0 -4
- data/spec/rails_app/app/views/posts/show.html.erb +0 -1
- data/spec/rails_app/config.ru +0 -4
- data/spec/rails_app/config/application.rb +0 -48
- data/spec/rails_app/config/boot.rb +0 -10
- data/spec/rails_app/config/database.yml +0 -25
- data/spec/rails_app/config/environment.rb +0 -5
- data/spec/rails_app/config/environments/development.rb +0 -32
- data/spec/rails_app/config/environments/production.rb +0 -62
- data/spec/rails_app/config/environments/test.rb +0 -41
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails_app/config/initializers/inflections.rb +0 -10
- data/spec/rails_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails_app/config/initializers/session_store.rb +0 -8
- data/spec/rails_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/rails_app/config/locales/en.yml +0 -5
- data/spec/rails_app/config/locales/loaf.en.yml +0 -6
- data/spec/rails_app/config/routes.rb +0 -7
- data/spec/rails_app/config/secrets.yml +0 -22
- data/spec/rails_app/public/404.html +0 -26
- data/spec/rails_app/public/422.html +0 -26
- data/spec/rails_app/public/500.html +0 -26
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/robots.txt +0 -5
- data/spec/spec_helper.rb +0 -52
- data/spec/support/capybara.rb +0 -8
- data/spec/support/dummy_controller.rb +0 -9
- data/spec/support/dummy_view.rb +0 -47
- data/spec/support/load_routes.rb +0 -4
- data/spec/unit/configuration_spec.rb +0 -39
- data/spec/unit/controller_extensions_spec.rb +0 -54
- data/spec/unit/crumb_formatter_spec.rb +0 -36
- data/spec/unit/crumb_spec.rb +0 -15
- data/spec/unit/generators/install_generator_spec.rb +0 -17
- data/spec/unit/options_validator_spec.rb +0 -15
- data/spec/unit/translation_spec.rb +0 -22
- data/spec/unit/view_extensions/breadcrumb_spec.rb +0 -22
- data/spec/unit/view_extensions/breadcrumb_trail_spec.rb +0 -232
- data/spec/unit/view_extensions/has_breadcrumbs_spec.rb +0 -10
- data/tasks/console.rake +0 -10
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'fileutils'
|
4
|
-
require 'generators/loaf/install_generator'
|
5
|
-
|
6
|
-
RSpec.describe Loaf::Generators::InstallGenerator, type: :generator do
|
7
|
-
destination File.expand_path("../../../tmp", __FILE__)
|
8
|
-
|
9
|
-
before { prepare_destination }
|
10
|
-
|
11
|
-
it "copies loaf locales to the host application" do
|
12
|
-
run_generator
|
13
|
-
locale = file("config/locales/loaf.en.yml")
|
14
|
-
expect(locale).to exist
|
15
|
-
FileUtils.rm_rf(File.expand_path("../../../tmp", __FILE__))
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::OptionsValidator, '.valid?' do
|
4
|
-
let(:klass) { Class.extend Loaf::OptionsValidator }
|
5
|
-
|
6
|
-
it 'validates succesfully known option' do
|
7
|
-
expect(klass.valid?(crumb_length: 10)).to eq(true)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'validates unknown option with an error' do
|
11
|
-
expect {
|
12
|
-
klass.valid?(invalid_param: true)
|
13
|
-
}.to raise_error(Loaf::InvalidOptions)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::Translation do
|
4
|
-
|
5
|
-
before { I18n.backend = I18n::Backend::Simple.new }
|
6
|
-
|
7
|
-
after { I18n.backend.reload! }
|
8
|
-
|
9
|
-
it 'translates breadcrumb title' do
|
10
|
-
I18n.backend.store_translations 'en', loaf: { breadcrumbs: { home: 'Home'}}
|
11
|
-
expect(described_class.find_title('home')).to eql('Home')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'does not translates breadcrumb name with missing scope' do
|
15
|
-
I18n.backend.store_translations 'en', breadcrumbs: {home: 'Home'}
|
16
|
-
expect(described_class.find_title('home')).to eql('home')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'translates breadcrumb name using default option' do
|
20
|
-
expect(described_class.find_title('home', default: 'breadcrumb default name')).to eql('breadcrumb default name')
|
21
|
-
end
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::ViewExtensions, '.breadcrumb' do
|
4
|
-
|
5
|
-
it { expect(DummyView.new).to respond_to(:add_breadcrumb) }
|
6
|
-
|
7
|
-
it 'creates crumb instance' do
|
8
|
-
instance = DummyView.new
|
9
|
-
name = 'Home'
|
10
|
-
url = :home_path
|
11
|
-
allow(Loaf::Crumb).to receive(:new).with(name, url, {})
|
12
|
-
instance.breadcrumb name, url
|
13
|
-
expect(Loaf::Crumb).to have_received(:new).with(name, url, {})
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'adds crumb to breadcrumbs storage' do
|
17
|
-
instance = DummyView.new
|
18
|
-
expect {
|
19
|
-
instance.breadcrumb 'Home', :home_path
|
20
|
-
}.to change { instance._breadcrumbs.size }.by(1)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,232 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::ViewExtensions, '#breadcrumb_trail' do
|
4
|
-
it "resolves breadcrumb paths" do
|
5
|
-
view = DummyView.new
|
6
|
-
view.breadcrumb('home', :home_path)
|
7
|
-
view.breadcrumb('posts', :posts_path)
|
8
|
-
view.set_path('/posts')
|
9
|
-
|
10
|
-
yielded = []
|
11
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
12
|
-
view.breadcrumb_trail(&block)
|
13
|
-
|
14
|
-
expect(yielded).to eq([
|
15
|
-
['home', '/', false],
|
16
|
-
['posts', '/posts', true]
|
17
|
-
])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "matches current path with :inclusive option as default" do
|
21
|
-
view = DummyView.new
|
22
|
-
view.breadcrumb('home', :home_path)
|
23
|
-
view.breadcrumb('posts', :posts_path)
|
24
|
-
view.set_path('/posts?id=73-title')
|
25
|
-
|
26
|
-
yielded = []
|
27
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
28
|
-
view.breadcrumb_trail(&block)
|
29
|
-
|
30
|
-
expect(yielded).to eq([
|
31
|
-
['home', '/', false],
|
32
|
-
['posts', '/posts', true]
|
33
|
-
])
|
34
|
-
end
|
35
|
-
|
36
|
-
it "matches current path with :inclusive when query params" do
|
37
|
-
view = DummyView.new
|
38
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
39
|
-
view.set_path('/posts?foo=bar')
|
40
|
-
|
41
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
42
|
-
end
|
43
|
-
|
44
|
-
it "matches current path with :inclusive when nested" do
|
45
|
-
view = DummyView.new
|
46
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
47
|
-
view.set_path('/posts/1/comment')
|
48
|
-
|
49
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
50
|
-
end
|
51
|
-
|
52
|
-
it "matches current path with :inclusive when nested" do
|
53
|
-
view = DummyView.new
|
54
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
55
|
-
view.set_path('/posts/1/comment')
|
56
|
-
|
57
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
58
|
-
end
|
59
|
-
|
60
|
-
it "doesn't match with :inclusive when unrelated path" do
|
61
|
-
view = DummyView.new
|
62
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
63
|
-
view.set_path('/post/1')
|
64
|
-
|
65
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
66
|
-
end
|
67
|
-
|
68
|
-
it "matches current path with :inclusive when extra trailing slash" do
|
69
|
-
view = DummyView.new
|
70
|
-
view.breadcrumb('posts', '/posts/', match: :inclusive)
|
71
|
-
view.set_path('/posts')
|
72
|
-
|
73
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts/', true]])
|
74
|
-
end
|
75
|
-
|
76
|
-
it "matches current path with :inclusive when absolute path" do
|
77
|
-
view = DummyView.new
|
78
|
-
view.breadcrumb('posts', 'http://www.example.com/posts/', match: :inclusive)
|
79
|
-
view.set_path('/posts')
|
80
|
-
|
81
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([
|
82
|
-
['posts', 'http://www.example.com/posts/', true]
|
83
|
-
])
|
84
|
-
end
|
85
|
-
|
86
|
-
it "matches current path with :exact when trailing slash" do
|
87
|
-
view = DummyView.new
|
88
|
-
view.breadcrumb('posts', '/posts/', match: :exact)
|
89
|
-
view.set_path('/posts')
|
90
|
-
|
91
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts/', true]])
|
92
|
-
end
|
93
|
-
|
94
|
-
it "fails to match current path with :exact when nested" do
|
95
|
-
view = DummyView.new
|
96
|
-
view.breadcrumb('posts', '/posts', match: :exact)
|
97
|
-
view.set_path('/posts/1/comment')
|
98
|
-
|
99
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
100
|
-
end
|
101
|
-
|
102
|
-
it "fails to match current path with :exact when query params" do
|
103
|
-
view = DummyView.new
|
104
|
-
view.breadcrumb('posts', '/posts', match: :exact)
|
105
|
-
view.set_path('/posts?foo=bar')
|
106
|
-
|
107
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
108
|
-
end
|
109
|
-
|
110
|
-
it "matches current path with :exclusive option when query params" do
|
111
|
-
view = DummyView.new
|
112
|
-
view.breadcrumb('posts', '/posts', match: :exclusive)
|
113
|
-
view.set_path('/posts?foo=bar')
|
114
|
-
|
115
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
116
|
-
end
|
117
|
-
|
118
|
-
it "fails to match current path with :exclusive option when nested" do
|
119
|
-
view = DummyView.new
|
120
|
-
view.breadcrumb('posts', '/posts', match: :exclusive)
|
121
|
-
view.set_path('/posts/1/comment')
|
122
|
-
|
123
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
124
|
-
end
|
125
|
-
|
126
|
-
it "matches current path with regex option when query params" do
|
127
|
-
view = DummyView.new
|
128
|
-
view.breadcrumb('posts', '/posts', match: %r{/po})
|
129
|
-
view.set_path('/posts?foo=bar')
|
130
|
-
|
131
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
132
|
-
end
|
133
|
-
|
134
|
-
it "matches current path with query params option" do
|
135
|
-
view = DummyView.new
|
136
|
-
view.breadcrumb('posts', '/posts', match: {foo: :bar})
|
137
|
-
view.set_path('/posts?foo=bar&baz=boo')
|
138
|
-
|
139
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
140
|
-
end
|
141
|
-
|
142
|
-
it "fails to match current path with query params option" do
|
143
|
-
view = DummyView.new
|
144
|
-
view.breadcrumb('posts', '/posts', match: {foo: :bar})
|
145
|
-
view.set_path('/posts?foo=2&baz=boo')
|
146
|
-
|
147
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
148
|
-
end
|
149
|
-
|
150
|
-
it "failse to recognize the match option" do
|
151
|
-
view = DummyView.new
|
152
|
-
view.breadcrumb('posts', 'http://www.example.com/posts/', match: :boom)
|
153
|
-
view.set_path('/posts')
|
154
|
-
block = -> (*args) { }
|
155
|
-
expect {
|
156
|
-
view.breadcrumb_trail(&block)
|
157
|
-
}.to raise_error(ArgumentError, "Unknown `:boom` match option!")
|
158
|
-
end
|
159
|
-
|
160
|
-
it "forces current path" do
|
161
|
-
view = DummyView.new
|
162
|
-
view.breadcrumb('home', :home_path)
|
163
|
-
view.breadcrumb('posts', :posts_path, match: :force)
|
164
|
-
view.set_path('/')
|
165
|
-
|
166
|
-
yielded = []
|
167
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
168
|
-
view.breadcrumb_trail(&block)
|
169
|
-
|
170
|
-
expect(yielded).to eq([
|
171
|
-
['home', '/', true],
|
172
|
-
['posts', '/posts', true]
|
173
|
-
])
|
174
|
-
end
|
175
|
-
|
176
|
-
it "returns enumerator without block" do
|
177
|
-
view = DummyView.new
|
178
|
-
view.breadcrumb('home', :home_path)
|
179
|
-
view.breadcrumb('posts', :posts_path)
|
180
|
-
view.set_path('/posts')
|
181
|
-
|
182
|
-
result = view.breadcrumb_trail
|
183
|
-
|
184
|
-
expect(result).to be_a(Enumerable)
|
185
|
-
expect(result.take(2).map(&:to_a)).to eq([
|
186
|
-
['home', '/', false],
|
187
|
-
['posts', '/posts', true]
|
188
|
-
])
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'validates passed options' do
|
192
|
-
view = DummyView.new
|
193
|
-
block = -> (name, url, styles) { }
|
194
|
-
expect {
|
195
|
-
view.breadcrumb_trail(unknown: true, &block)
|
196
|
-
}.to raise_error(Loaf::InvalidOptions)
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'uses global configuration for crumb formatting' do
|
200
|
-
allow(Loaf.configuration).to receive(:crumb_length).and_return(10)
|
201
|
-
view = DummyView.new
|
202
|
-
view.breadcrumb('home-sweet-home', :home_path)
|
203
|
-
view.breadcrumb('posts-for-everybody', :posts_path)
|
204
|
-
view.set_path('/posts')
|
205
|
-
|
206
|
-
yielded = []
|
207
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
208
|
-
view.breadcrumb_trail(&block)
|
209
|
-
|
210
|
-
expect(yielded).to eq([
|
211
|
-
['home-sw...', '/', false],
|
212
|
-
['posts-f...', '/posts', true]
|
213
|
-
])
|
214
|
-
end
|
215
|
-
|
216
|
-
it "allows to overwrite global configuration" do
|
217
|
-
allow(Loaf.configuration).to receive(:crumb_length).and_return(10)
|
218
|
-
view = DummyView.new
|
219
|
-
view.breadcrumb('home-sweet-home', :home_path)
|
220
|
-
view.breadcrumb('posts-for-everybody', :posts_path)
|
221
|
-
view.set_path('/posts')
|
222
|
-
|
223
|
-
yielded = []
|
224
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
225
|
-
view.breadcrumb_trail(crumb_length: 15, &block)
|
226
|
-
|
227
|
-
expect(yielded).to eq([
|
228
|
-
['home-sweet-home', '/', false],
|
229
|
-
['posts-for-ev...', '/posts', true]
|
230
|
-
])
|
231
|
-
end
|
232
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::ViewExtensions, '.breadcrumb?' do
|
4
|
-
it 'checks for breadcrumbs existance' do
|
5
|
-
instance = DummyView.new
|
6
|
-
expect(instance.breadcrumbs?).to eq(false)
|
7
|
-
instance.breadcrumb 'Home', :home_path
|
8
|
-
expect(instance.breadcrumbs?).to eq(true)
|
9
|
-
end
|
10
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|