hensel 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acc9a789f685382612bac321c291e9cfe1d5b42d
4
- data.tar.gz: 3e0e9e435e490ded71fc8d64ed87809b3d95d6e7
3
+ metadata.gz: 434fd86c664651d5add6279752d7bdd88ba43811
4
+ data.tar.gz: cbcd4a4e68e8973afe2b3543797ae000500c39f2
5
5
  SHA512:
6
- metadata.gz: b007e8ef81416d5e682c50d848f71d87d24cefda9d0b4ca06998d8d9297acf6cb6765f9e5948796b101ec5431f54c2b8b8f51b3fdd23487c72e8e299f46eb143
7
- data.tar.gz: 3077a490553b985be304c173a9a31552a564a5c457c0d9ac34ee340fc47f38c4f5e982d44589c8e2c9cbe55381d68fc68a29ace895b74d16cd4201312d809a3e
6
+ metadata.gz: 03019e883e2ac450fbacffb914ff6caaf2e413b955f8de2e527b5555f487f48e74fca50f6e3edbbaa6b2be66f3bd95fad3855d893129e35b69212992032a06ef
7
+ data.tar.gz: 0f9f258dab021ec00b7f5db5217b5b23e8c7a758361df9e5939a9ca8f721a74a525ae07f448582fedc72596b8bcaf370af41292a31fd891c7c8c998036eeabb7
data/README.md CHANGED
@@ -39,15 +39,17 @@ require 'hensel'
39
39
 
40
40
  Hensel.configure do |config|
41
41
  # Default values
42
- config.bootstrap = false
43
- config.escape_html = true
44
- config.indentation = true
45
- config.last_item_link = false
46
- config.richsnippet = :microdata
47
- config.attr_wrapper = "'"
48
- config.whitespace = " "
49
- config.parent_element = :ul
50
- config.before_load = nil
42
+ config.bootstrap = false
43
+ config.escape_html = true
44
+ config.indentation = true
45
+ config.last_item_link = false
46
+ config.richsnippet = :microdata
47
+ config.attr_wrapper = "'"
48
+ config.whitespace = " "
49
+ config.parent_element = :ul
50
+ config.before_load = nil
51
+ config.default_item_options = {}
52
+ config.parent_attributes = {}
51
53
  end
52
54
  ```
53
55
 
@@ -201,6 +203,22 @@ home.text #=> "Home"
201
203
  home.url #=> "/"
202
204
  ```
203
205
 
206
+ **If Hash is set to `default_item_options`, all items will use it as options.
207
+
208
+ ```ruby
209
+ Hensel.configuration.default_item_options = { class: "tested" }
210
+ builder = Hensel::Builder.new
211
+ builder.add("Home", "/")
212
+ builder.items.first.render #=> "<li class='tested'><a href='/'>Home</a></li>"
213
+ ```
214
+
215
+ **If Hash is set to `parent_attributes`, the parent element will include it as attributes.
216
+
217
+ ```ruby
218
+ Hensel.configuration.parent_attributes = { class: "parent-tested" }
219
+ builder = Hensel::Builder.new
220
+ builder.render #=> "<ul class='parent-tested'></ul>"
221
+ ```
204
222
 
205
223
  ### Builder
206
224
 
@@ -10,7 +10,7 @@ module Hensel
10
10
 
11
11
  def initialize(**options)
12
12
  @items = []
13
- @options = options
13
+ @options = options.empty? ? Hensel.configuration.parent_attributes.dup : options
14
14
  instance_eval(&Hensel.configuration.before_load) if Hensel.configuration.before_load
15
15
  end
16
16
 
@@ -65,11 +65,11 @@ module Hensel
65
65
  items_length = items.length.pred
66
66
  items.map.with_index do |item, index|
67
67
  if index == items_length
68
- item._last = true
68
+ item.is_last = true
69
69
  elsif index.zero?
70
- item._first = true
70
+ item.is_first = true
71
71
  else
72
- item._first = item._last = false
72
+ item.is_first = item.is_last = false
73
73
  end
74
74
  item_filters.each{|filter| item.instance_eval(&filter) } unless item_filters.empty?
75
75
  yield item
@@ -98,6 +98,8 @@ module Hensel
98
98
  when 1
99
99
  if (options = arguments.first) && options.instance_of?(Hash)
100
100
  [ options.delete(:text) || options.delete(:content), options.delete(:path) || options.delete(:url), options ]
101
+ elsif options.instance_of?(String)
102
+ [ options, nil, {} ]
101
103
  else
102
104
  raise ArgumentError
103
105
  end
@@ -7,14 +7,14 @@ module Hensel
7
7
  extend Forwardable
8
8
 
9
9
  attr_accessor :text, :url, :options
10
- attr_accessor :_first, :_last, :renderer
10
+ attr_accessor :is_first, :is_last, :renderer
11
11
 
12
12
  def_delegators :@options, :[], :[]=
13
13
 
14
14
  def initialize(text, url, **options)
15
15
  @text = h(text)
16
16
  @url = url
17
- @options = options
17
+ @options = Hensel.configuration.default_item_options.merge(options)
18
18
  end
19
19
 
20
20
  def render
@@ -32,11 +32,11 @@ module Hensel
32
32
  end
33
33
 
34
34
  def first?
35
- !!_first
35
+ !!is_first
36
36
  end
37
37
 
38
38
  def last?
39
- !!_last
39
+ !!is_last
40
40
  end
41
41
  end
42
42
  end
@@ -13,18 +13,21 @@ module Hensel
13
13
  attr_boolean_accessor :indentation
14
14
  attr_boolean_accessor :last_item_link
15
15
 
16
- attr_accessor :attr_wrapper, :whitespace, :parent_element, :richsnippet, :before_load
16
+ attr_accessor :attr_wrapper, :whitespace, :parent_element, :richsnippet, :before_load,
17
+ :default_item_options, :parent_attributes
17
18
 
18
19
  def initialize
19
- @bootstrap = false
20
- @escape_html = true
21
- @indentation = true
22
- @last_item_link = false
23
- @richsnippet = :microdata # [:microdata, :rdfa, :nil]
24
- @attr_wrapper = "'"
25
- @whitespace = " "
26
- @parent_element = :ul
27
- @before_load = nil
20
+ @bootstrap = false
21
+ @escape_html = true
22
+ @indentation = true
23
+ @last_item_link = false
24
+ @richsnippet = :microdata # [:microdata, :rdfa, :nil]
25
+ @attr_wrapper = "'"
26
+ @whitespace = " "
27
+ @parent_element = :ul
28
+ @before_load = nil
29
+ @default_item_options = {}
30
+ @parent_attributes = {}
28
31
  end
29
32
 
30
33
  def [](key)
@@ -1,3 +1,3 @@
1
1
  module Hensel
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -37,6 +37,19 @@ describe Hensel::Builder do
37
37
  expect(builder.render).to have_tag(:li, class: "optional-class", id: "foo-id")
38
38
  end
39
39
  end
40
+
41
+ context "with one argument" do
42
+ it "returns an instance of Builder::Item" do
43
+ expect(builder.add("Index")).to be_an_instance_of(Hensel::Builder::Item)
44
+ end
45
+
46
+ it "adds an instance of Builder::Item to items" do
47
+ builder.add("Boom")
48
+ expect(builder.items.last).to be_an_instance_of(Hensel::Builder::Item)
49
+ expect(builder.items.last.text).to eq("Boom")
50
+ expect(builder.items.last.url).to be_nil
51
+ end
52
+ end
40
53
  end
41
54
 
42
55
  describe "#remove" do
@@ -45,7 +58,7 @@ describe Hensel::Builder do
45
58
  tested = builder.add("Tested", "/tested")
46
59
  builder.add("Sample", "/sample")
47
60
  builder.remove("Tested")
48
- expect(builder.items.any?{|x| x.text == tested.text }).to be_false
61
+ expect(builder.items.any?{|x| x.text == tested.text }).to be_falsey
49
62
  end
50
63
  end
51
64
 
@@ -54,8 +67,8 @@ describe Hensel::Builder do
54
67
  tested = builder.add("Tested", "/tested")
55
68
  sample = builder.add("Sample", "/sample")
56
69
  builder.remove{|x| x.url == "/sample" }
57
- expect(builder.items.any?{|x| x.text == tested.text }).to be_true
58
- expect(builder.items.any?{|x| x.text == sample.text }).to be_false
70
+ expect(builder.items.any?{|x| x.text == tested.text }).to be_truthy
71
+ expect(builder.items.any?{|x| x.text == sample.text }).to be_falsey
59
72
  end
60
73
  end
61
74
  end
@@ -128,8 +141,8 @@ describe Hensel::Builder do
128
141
  before { Hensel.configuration.attr_wrapper = '"' }
129
142
  before(:each){ builder.add("Index", "/", class: "dummy-class") }
130
143
  subject { builder.render }
131
- it { should_not match(/'/) }
132
- it { should match(/"/) }
144
+ it { is_expected.not_to match(/'/) }
145
+ it { is_expected.to match(/"/) }
133
146
  after { Hensel.reset_configuration! }
134
147
  end
135
148
 
@@ -151,7 +164,7 @@ describe Hensel::Builder do
151
164
  FIXTURE
152
165
  }
153
166
  subject { builder.render }
154
- it { should eq(fixture) }
167
+ it { is_expected.to eq(fixture) }
155
168
  end
156
169
  end
157
170
 
@@ -199,4 +212,16 @@ describe Hensel::Builder do
199
212
  end
200
213
  end
201
214
  end
215
+
216
+ describe "configure attributes of the parent element" do
217
+ before do
218
+ Hensel.configuration.parent_attributes = { class: "breadcrumbs", style: "border:0" }
219
+ builder.add("Index", "/")
220
+ end
221
+ subject{ builder.render }
222
+
223
+ it "can set attributes of the parent element" do
224
+ expect(subject).to have_tag(:ul, with: { class: "breadcrumbs", style: "border:0" })
225
+ end
226
+ end
202
227
  end
@@ -5,9 +5,9 @@ describe Hensel::Configuration do
5
5
  let(:variables){ configuration.instance_variables.map{|v| v[1..-1] } }
6
6
  describe ".attr_boolean_accessor" do
7
7
  it "can define an accessor and boolean methods" do
8
- expect(configuration.respond_to?(:sample)).to be_false
8
+ expect(configuration.respond_to?(:sample)).to be_falsey
9
9
  Hensel::Configuration.attr_boolean_accessor :sample
10
- expect(configuration.respond_to?(:sample)).to be_true
10
+ expect(configuration.respond_to?(:sample)).to be_truthy
11
11
  end
12
12
  end
13
13
 
data/spec/helpers_spec.rb CHANGED
@@ -4,5 +4,5 @@ describe Hensel::Helpers do
4
4
  let(:object){ Object.new }
5
5
  before { object.extend Hensel::Helpers }
6
6
  subject{ object.breadcrumbs }
7
- it { should be_an_instance_of(Hensel::Builder) }
7
+ it { is_expected.to be_an_instance_of(Hensel::Builder) }
8
8
  end
data/spec/item_spec.rb CHANGED
@@ -10,7 +10,7 @@ describe Hensel::Builder::Item do
10
10
  end
11
11
  before(:each){ builder.add('\'&"<>', '/') }
12
12
  subject { builder.items.last.text }
13
- it { should eq('&#39;&amp;&quot;&lt;&gt;') }
13
+ it { is_expected.to eq('&#39;&amp;&quot;&lt;&gt;') }
14
14
  end
15
15
 
16
16
  context "without escape_html" do
@@ -20,21 +20,37 @@ describe Hensel::Builder::Item do
20
20
  end
21
21
  before(:each){ builder.add('\'&"<>', '/') }
22
22
  subject { builder.items.last.text }
23
- it { should eq('\'&"<>') }
23
+ it { is_expected.to eq('\'&"<>') }
24
24
  end
25
25
 
26
26
  describe "#render" do
27
27
  let(:item) { Hensel::Builder::Item.new("index", "/") }
28
28
  subject { item.render }
29
29
  context "basic usage" do
30
- it { should have_tag(:li){ with_tag(:a, href: "/") } }
30
+ it { is_expected.to have_tag(:li){ with_tag(:a, href: "/") } }
31
31
  end
32
32
 
33
33
  context "with customized renderer" do
34
34
  it "can be set to renderer" do
35
35
  item.renderer = ->(this){ node(:custom, data: "sample"){ item.text } }
36
- should have_tag(:custom, text: "index", data: "sample")
36
+ is_expected.to have_tag(:custom, text: "index", data: "sample")
37
37
  end
38
38
  end
39
39
  end
40
+
41
+ describe "default_item_options" do
42
+ before do
43
+ Hensel.configuration.default_item_options = { class: "default-item" }
44
+ end
45
+ let(:item) { Hensel::Builder::Item.new("index", "/", class: "custom-item") }
46
+ subject { item.render }
47
+
48
+ it "can set hash as default item options" do
49
+ is_expected.to have_tag(:li, class: "default-item")
50
+ end
51
+
52
+ it "should overwrite the options" do
53
+ is_expected.to have_tag(:li, class: "custom-item")
54
+ end
55
+ end
40
56
  end
data/spec/node_spec.rb CHANGED
@@ -12,12 +12,12 @@ describe Hensel::Builder::Node do
12
12
  subject { item.render }
13
13
  it "can build html correctly" do
14
14
  item.renderer = ->(this){ node(:div, class: "hey"){ "sample text" }}
15
- should have_tag(:div, text: "sample text", class: "hey")
15
+ is_expected.to have_tag(:div, text: "sample text", class: "hey")
16
16
  end
17
17
 
18
18
  it "can build html correctly even when node is nested" do
19
19
  item.renderer = ->(this){ node(:div, class: "hey"){ node(:span){ "nested text" } }}
20
- should have_tag(:div, class: "hey") do
20
+ is_expected.to have_tag(:div, class: "hey") do
21
21
  with_tag(:span, text: "nested text")
22
22
  end
23
23
  end
@@ -29,7 +29,7 @@ describe Hensel::Builder::Node do
29
29
  node(:span){ "one2" }
30
30
  end
31
31
  }
32
- should have_tag(:div) do
32
+ is_expected.to have_tag(:div) do
33
33
  with_tag(:span, text: "one1")
34
34
  with_tag(:span, text: "one2")
35
35
  end
@@ -40,12 +40,12 @@ describe Hensel::Builder::Node do
40
40
  subject { item.render }
41
41
  it "can build html correctly" do
42
42
  item.renderer = ->(this){ node(:div, "sample text", class: "hey") }
43
- should have_tag(:div, content: "sample text", class: "hey")
43
+ is_expected.to have_tag(:div, content: "sample text", class: "hey")
44
44
  end
45
45
 
46
46
  it "can build html correctly even when node is nested" do
47
47
  item.renderer = ->(this){ node(:div, class: "hey"){ node(:span, "nested text") }}
48
- should have_tag(:div, class: "hey") do
48
+ is_expected.to have_tag(:div, class: "hey") do
49
49
  with_tag(:span, content: "nested text")
50
50
  end
51
51
  end
@@ -57,7 +57,7 @@ describe Hensel::Builder::Node do
57
57
  node(:span, "one2")
58
58
  end
59
59
  }
60
- should have_tag(:div) do
60
+ is_expected.to have_tag(:div) do
61
61
  with_tag(:span, text: "one1")
62
62
  with_tag(:span, text: "one2")
63
63
  end
@@ -69,7 +69,7 @@ describe Hensel::Builder::Node do
69
69
  subject { item.render }
70
70
  it "can be referred from block" do
71
71
  item.renderer = ->(this){ node(:div, item.text) }
72
- should have_tag(:div, text: "index")
72
+ is_expected.to have_tag(:div, text: "index")
73
73
  end
74
74
  end
75
75
  end
@@ -7,35 +7,35 @@ describe Hensel::Helpers::TagHelpers do
7
7
  describe "#contegt_tag" do
8
8
  context "with block" do
9
9
  subject { helpers.content_tag(:div, class: "dummy-class"){ "hello" }}
10
- it { should have_tag(:div, content: "hello", class: "dummy-class") }
10
+ it { is_expected.to have_tag(:div, content: "hello", class: "dummy-class") }
11
11
  end
12
12
 
13
13
  context "without block" do
14
14
  subject { helpers.content_tag(:div, "hello", class: "dummy-class")}
15
- it { should have_tag(:div, content: "hello", class: "dummy-class") }
15
+ it { is_expected.to have_tag(:div, content: "hello", class: "dummy-class") }
16
16
  end
17
17
 
18
18
  context "with indentation" do
19
19
  before { Hensel.configuration.indentation = true }
20
20
  subject { helpers.content_tag(:div, "hello", indent: 2, class: "dummy-class")}
21
- it { expect(subject.start_with?(" ")).to be_true }
21
+ it { expect(subject.start_with?(" ")).to be_truthy }
22
22
  end
23
23
 
24
24
  context "without indentation" do
25
25
  before { Hensel.configuration.indentation = false }
26
26
  subject { helpers.content_tag(:div, "hello", indent: 2, class: "dummy-class")}
27
- it { expect(subject.start_with?("<div")).to be_true }
27
+ it { expect(subject.start_with?("<div")).to be_truthy }
28
28
  end
29
29
  end
30
30
 
31
31
  describe "#tag" do
32
32
  subject { helpers.tag(:img, class: "sample-image", src: "sample.jpg", alt: "sample image") }
33
- it { should have_tag(:img, class: "sample-image", src: "sample.jpg", alt: "sample image") }
33
+ it { is_expected.to have_tag(:img, class: "sample-image", src: "sample.jpg", alt: "sample image") }
34
34
  end
35
35
 
36
36
  describe "#append_attribute" do
37
37
  subject { Hash.new }
38
38
  before { helpers.append_attribute(:key, :value, subject) }
39
- it { subject[:key].should eq(:value) }
39
+ it { expect(subject[:key]).to eq(:value) }
40
40
  end
41
41
  end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hensel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - namusyaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nyan-cat-formatter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-shell
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Hensel makes it easy to build the breadcrumbs.
@@ -115,8 +115,8 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".gitignore"
119
- - ".travis.yml"
118
+ - .gitignore
119
+ - .travis.yml
120
120
  - Gemfile
121
121
  - Guardfile
122
122
  - LICENSE.txt
@@ -152,17 +152,17 @@ require_paths:
152
152
  - lib
153
153
  required_ruby_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - ">="
155
+ - - '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  requirements:
160
- - - ">="
160
+ - - '>='
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
164
  rubyforge_project:
165
- rubygems_version: 2.2.2
165
+ rubygems_version: 2.0.14
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: Hensel makes it easy to build the breadcrumbs.