tiny 0.2.7 → 0.2.8

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
- SHA1:
3
- metadata.gz: 0a25f5692ba1dfbb0a1d206402dc725ef45c0493
4
- data.tar.gz: c520045fc273ddb2257ce4e6fe6047bd3513da39
2
+ SHA256:
3
+ metadata.gz: fe8e793ac657e2b7412bf405aac9039b1306db27c7cb2e06a23a963c43f42e19
4
+ data.tar.gz: 32280a75554bd9688324a4806baa6639022640962ab71cb9404381c4be7bc5f1
5
5
  SHA512:
6
- metadata.gz: 98043c8f9fd4d1cc7a19a06c11f5c617797228a854119636551490192aa7688a63fa374539ffb1cf6c015b1730b3625a0bd5a8173469490186068a02b003b15c
7
- data.tar.gz: 020ea10b6826e86b562f0d99e1dcd58f998f70a721e5b18f2610911f30e2bdf5cf1a027ae6fa901d01490017f5474d2adf81ff9abad82e7b8705668ecba10133
6
+ metadata.gz: c1acfa8d3983082fa4a3f3e197ec417d52dec82cec0697dd1890bd9928aa8db84e5d827df4a5b1fa26dd09f853dcc64c4aa4b33a042fc9a964e4c08dc72a35b2
7
+ data.tar.gz: 30d01e45e02202bc1d6f8be89d9e45303a5678b0e0b82d676ea6d41b156d6ae6ae7446858d47c0a4215852c0c88b088a11a8f701596e6bb021e2983865726443
@@ -108,7 +108,7 @@ module Tiny
108
108
  # </form>
109
109
  #
110
110
  #
111
- def html_tag name, attrs_or_content = {}, attrs = nil, &block
111
+ def html_tag(name, attrs_or_content = {}, attrs = nil, &block)
112
112
  append! Tag.new(name, attrs_or_content, attrs).render(&block)
113
113
  end
114
114
 
@@ -123,7 +123,7 @@ module Tiny
123
123
  #
124
124
  # @return [SafeString] HTML content.
125
125
  #
126
- def comment content
126
+ def comment(content)
127
127
  append! "<!-- #{content.to_s.gsub(/-(?=-)/, '- ')} -->"
128
128
  end
129
129
 
@@ -138,7 +138,7 @@ module Tiny
138
138
  #
139
139
  # @return [String] CDATA section.
140
140
  #
141
- def cdata content
141
+ def cdata(content)
142
142
  content = content.to_s.gsub(']]>', ']]]]><![CDATA[>')
143
143
  append! "<![CDATA[#{content}]]>"
144
144
  end
@@ -178,7 +178,7 @@ module Tiny
178
178
  #
179
179
  # @return [String] HTML-escaped.
180
180
  #
181
- def append string
181
+ def append(string)
182
182
  string = Helpers.sanitize(string)
183
183
  if working_buffer
184
184
  working_buffer << string.gsub(/(?<!^|\n)\z/, "\n")
@@ -205,7 +205,7 @@ module Tiny
205
205
  #
206
206
  # @return [SafeString] Non HTML-escaped.
207
207
  #
208
- def append! content
208
+ def append!(content)
209
209
  append raw(content)
210
210
  end
211
211
  alias text! append!
@@ -214,7 +214,7 @@ module Tiny
214
214
  #
215
215
  # @return [SafeString] Considered html safe.
216
216
  #
217
- def raw val
217
+ def raw(val)
218
218
  SafeString.new val.to_s
219
219
  end
220
220
 
@@ -246,13 +246,14 @@ module Tiny
246
246
  #
247
247
  # @return [String] HTML markup.
248
248
  #
249
- def with_buffer *args, &block
249
+ def with_buffer(*args)
250
250
  buffer_stack << ''
251
- yield *args
251
+ yield(*args)
252
252
  buffer_stack.pop
253
253
  end
254
254
 
255
255
  private
256
+
256
257
  # Pushing and popping.
257
258
  def buffer_stack
258
259
  @buffer_stack ||= []
@@ -278,7 +279,7 @@ module Tiny
278
279
  # @yield [*args] HAML block or content block.
279
280
  # @return [String] HTML markup.
280
281
  #
281
- def with_buffer *args, &block
282
+ def with_buffer(*args, &block)
282
283
  defined?(Haml) && Haml::Helpers.block_is_haml?(block) ? capture_haml(*args, &block) : super
283
284
  end
284
285
  end
@@ -297,7 +298,7 @@ module Tiny
297
298
  # @yield [*args] ERB block or content block.
298
299
  # @return [String] HTML markup.
299
300
  #
300
- def with_buffer *args, &block
301
+ def with_buffer(*args, &block)
301
302
  erb_block?(block) ? capture_erb(*args, &block) : super
302
303
  end
303
304
 
@@ -307,7 +308,7 @@ module Tiny
307
308
  # @return [String] HTML markup
308
309
  # @yield [*args]
309
310
  #
310
- def capture_erb *args, &block
311
+ def capture_erb(*args, &block)
311
312
  output_buffer = eval('_buf', block.binding)
312
313
  buffer = output_buffer.dup
313
314
  output_buffer.clear and yield(*args)
@@ -320,7 +321,7 @@ module Tiny
320
321
  #
321
322
  # @param block [Proc] a Proc object
322
323
  #
323
- def erb_block? block
324
+ def erb_block?(block)
324
325
  block && eval('defined?(__in_erb_template)', block.binding)
325
326
  end
326
327
  end
@@ -337,7 +338,7 @@ module Tiny
337
338
  #
338
339
  # @return [String] HTML markup
339
340
  #
340
- def tag name, attrs_or_content = {}, attrs = nil, &block
341
+ def tag(name, attrs_or_content = {}, attrs = nil, &block)
341
342
  html_tag name, attrs_or_content, attrs, &block
342
343
  end
343
344
 
@@ -348,7 +349,7 @@ module Tiny
348
349
  # @param value [String, Object]
349
350
  # @return [String]
350
351
  #
351
- def self.sanitize value
352
+ def self.sanitize(value)
352
353
  if value.respond_to?(:html_safe?) && value.html_safe?
353
354
  value.to_s
354
355
  else
@@ -356,7 +357,7 @@ module Tiny
356
357
  end
357
358
  end
358
359
 
359
- def self.escape_html html
360
+ def self.escape_html(html)
360
361
  CGI.escapeHTML html.to_s
361
362
  end
362
363
  end
@@ -414,7 +415,7 @@ module Tiny
414
415
  # @return [String] HTML markup.
415
416
  # @see Widget.
416
417
  #
417
- def render &block
418
+ def render(&block)
418
419
  output = with_buffer do
419
420
  next markup unless block_given?
420
421
  markup do |args|
@@ -440,18 +441,18 @@ module Tiny
440
441
  # @yield [*args] HAML block or content block.
441
442
  # @return [String] HTML markup.
442
443
  #
443
- def with_buffer *args, &block
444
+ def with_buffer(*args, &block)
444
445
  block_from_template?(block) ? capture(*args, &block) : super
445
446
  end
446
447
 
447
448
  # Appends sanitized text to the content.
448
449
  # @see Buffering#append
449
- def append markup
450
+ def append(markup)
450
451
  super(markup).html_safe
451
452
  end
452
453
 
453
454
  # Returns true if the block was originated in an ERB or HAML template.
454
- def block_from_template? block
455
+ def block_from_template?(block)
455
456
  block && eval('defined?(output_buffer)', block.binding) == 'local-variable'
456
457
  end
457
458
  end
@@ -14,22 +14,22 @@ module Tiny
14
14
  module Erubis
15
15
  # @see Erubis
16
16
  class ::String
17
- def append= obj
17
+ def append=(obj)
18
18
  self << obj.to_s
19
19
  end
20
20
 
21
- def append_escaped= obj
21
+ def append_escaped=(obj)
22
22
  self << Tiny::Helpers.sanitize(obj.to_s)
23
23
  end
24
24
  end
25
25
 
26
26
  # @see Erubis
27
27
  module ErubyExtensions
28
- def add_expr_literal src, code
28
+ def add_expr_literal(src, code)
29
29
  src << "_buf.append= #{code};"
30
30
  end
31
31
 
32
- def add_expr_escaped src, code
32
+ def add_expr_escaped(src, code)
33
33
  src << "_buf.append_escaped= #{code};"
34
34
  end
35
35
  end
@@ -49,11 +49,11 @@ module Tiny
49
49
  def prepare
50
50
  engine_class = options.delete(:engine_class) || Eruby
51
51
  engine_class = EscapedEruby if options.delete(:escape_html)
52
- options.merge!(:engine_class => engine_class)
52
+ options.merge!(engine_class: engine_class)
53
53
  super
54
54
  end
55
55
 
56
- def precompiled_preamble locals
56
+ def precompiled_preamble(locals)
57
57
  [super, "__in_erb_template=true"].join("\n")
58
58
  end
59
59
  end
@@ -7,18 +7,15 @@ module Tiny
7
7
  # Void tag names.
8
8
  # Tags that should have no content.
9
9
  # @return [Array]
10
- def content_tags
11
- @content_tags
12
- end
10
+ attr_reader :content_tags
13
11
 
14
12
  # Content tag names.
15
13
  # Tags that can have content.
16
14
  # @return [Array]
17
- def void_tags
18
- @void_tags
19
- end
15
+ attr_reader :void_tags
20
16
 
21
17
  private
18
+
22
19
  # @macro tag_def
23
20
  # @method $1(attrs_or_content = {}, attrs = nil, &block)
24
21
  # Shortcut for {Markup#html_tag html_tag}(:$1)
@@ -30,7 +27,7 @@ module Tiny
30
27
  #
31
28
  # @see Markup#html_tag
32
29
  #
33
- def tag_def tag_name, void_tag = false
30
+ def tag_def(tag_name, void_tag = false)
34
31
  class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
35
32
  def #{tag_name} *args, &block
36
33
  html_tag "#{tag_name}", *args, &block
@@ -8,7 +8,7 @@ module Tiny
8
8
  class SafeString < String
9
9
  def html_safe?; true end
10
10
 
11
- def concat string
11
+ def concat(string)
12
12
  return super unless String === string
13
13
  super Helpers.sanitize string
14
14
  end
@@ -2,9 +2,9 @@ module Tiny
2
2
  # @see Markup#html_tag
3
3
  class Tag
4
4
  attr_reader :tag_name, :attrs
5
- def initialize tag_name, aoc = {}, attrs = nil
5
+ def initialize(tag_name, aoc = {}, attrs = nil)
6
6
  @attrs, @content =
7
- Hash === aoc && attrs.nil?? [aoc] : [attrs || {}, aoc]
7
+ Hash === aoc && attrs.nil? ? [aoc] : [attrs || {}, aoc]
8
8
  @content = Helpers.sanitize(@content) if @content
9
9
  @tag_name = tag_name
10
10
  end
@@ -18,13 +18,13 @@ module Tiny
18
18
  Helpers.escape_html value
19
19
  end
20
20
 
21
- %{#{name}="#{vals.join(' ')}"}
21
+ %(#{name}="#{vals.join(' ')}")
22
22
  end.compact.join(' ')
23
23
 
24
24
  " #{tag_attrs}" unless tag_attrs.empty?
25
25
  end
26
26
 
27
- def render &block
27
+ def render(&block)
28
28
  if void_tag?
29
29
  "<#{tag_name}#{tag_attributes} />"
30
30
  else
@@ -1,3 +1,3 @@
1
1
  module Tiny
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -12,17 +12,17 @@ describe 'markup helpers' do
12
12
  end
13
13
 
14
14
  it 'should use tiny escaped erubis engine for escaping html' do
15
- engine = Tilt['erb'].new(nil, :escape_html => true){}.instance_variable_get(:@engine)
15
+ engine = Tilt['erb'].new(nil, escape_html: true){}.instance_variable_get(:@engine)
16
16
  expect(engine).to be_a Tiny::Erubis::EscapedEruby
17
17
  end
18
18
 
19
19
  it 'should escape html when passing :escape_html => true option' do
20
- template = Tilt['erb'].new(nil, :escape_html => true) { %(<%= "<p>Hello World!</p>" %>) }
20
+ template = Tilt['erb'].new(nil, escape_html: true) { %(<%= "<p>Hello World!</p>" %>) }
21
21
  expect(template.render).to eq("&lt;p&gt;Hello World!&lt;/p&gt;")
22
22
  end
23
23
 
24
24
  it 'should not escape htmle when passing :escape_html => false option' do
25
- template = Tilt['erb'].new(nil, :escape_html => false) { %(<%= "<p>Hello World!</p>" %>) }
25
+ template = Tilt['erb'].new(nil, escape_html: false) { %(<%= "<p>Hello World!</p>" %>) }
26
26
  expect(template.render).to eq("<p>Hello World!</p>")
27
27
  end
28
28
 
@@ -37,7 +37,7 @@ describe 'markup helpers' do
37
37
  end
38
38
 
39
39
  it 'should allow block with explicit output' do
40
- template = Tilt['erb'].new nil, :escape_html => true do
40
+ template = Tilt['erb'].new nil, escape_html: true do
41
41
  <<-ERB
42
42
  <%= [1,2].each do |i| %>
43
43
  <% end %>
@@ -12,16 +12,16 @@ describe 'markup helpers' do
12
12
  describe 'basic' do
13
13
  describe 'attributes and content' do
14
14
  before do
15
- @output = tag(:li, :class => 'item', :id => 'hello') { text 'Hello' }
15
+ @output = tag(:li, class: 'item', id: 'hello') { text 'Hello' }
16
16
  end
17
- it { expect(output).to have_css 'li', :count => 1 }
18
- it { expect(output).to have_css 'li', :text => "Hello" }
17
+ it { expect(output).to have_css 'li', count: 1 }
18
+ it { expect(output).to have_css 'li', text: "Hello" }
19
19
  it { expect(output).to have_css 'li.item' }
20
20
  it { expect(output).to have_css 'li#hello' }
21
21
  end
22
22
 
23
23
  it 'should not use blank attribute values' do
24
- output = tag(:li, :class => [], :id => nil)
24
+ output = tag(:li, class: [], id: nil)
25
25
  expect(output).to eq("<li></li>")
26
26
  end
27
27
 
@@ -41,18 +41,18 @@ describe 'markup helpers' do
41
41
  end
42
42
 
43
43
  it 'should output multiple classes passing an array' do
44
- output = tag(:li, :class => %w(item in-stock))
44
+ output = tag(:li, class: %w(item in-stock))
45
45
  expect(output).to eq('<li class="item in-stock"></li>')
46
46
  end
47
47
 
48
48
  it 'should allow passing content as string' do
49
49
  expect(tag(:h1, "Hello")).to eq("<h1>Hello</h1>")
50
- expect(tag(:h1, "Hello", :class => 'main')).to eq(%{<h1 class="main">Hello</h1>})
50
+ expect(tag(:h1, "Hello", class: 'main')).to eq(%(<h1 class="main">Hello</h1>))
51
51
  end
52
52
 
53
53
  it 'should escape attribute html' do
54
- expect(tag(:a, :href => '<script>')).to eq('<a href="&lt;script&gt;"></a>')
55
- expect(tag(:a, :href => 'art&copy')).to eq('<a href="art&amp;copy"></a>')
54
+ expect(tag(:a, href: '<script>')).to eq('<a href="&lt;script&gt;"></a>')
55
+ expect(tag(:a, href: 'art&copy')).to eq('<a href="art&amp;copy"></a>')
56
56
  end
57
57
  end
58
58
 
@@ -61,9 +61,9 @@ describe 'markup helpers' do
61
61
  before do
62
62
  @output = tag(:div) { tag(:a) { text 'Hello' } }
63
63
  end
64
- it { expect(output).to have_css 'div', :count => 1 }
65
- it { expect(output).to have_css 'a', :count => 1 }
66
- it { expect(output).to have_css 'div > a', :text => 'Hello' }
64
+ it { expect(output).to have_css 'div', count: 1 }
65
+ it { expect(output).to have_css 'a', count: 1 }
66
+ it { expect(output).to have_css 'div > a', text: 'Hello' }
67
67
  end
68
68
 
69
69
  describe 'deeper blocks' do
@@ -75,11 +75,11 @@ describe 'markup helpers' do
75
75
  end
76
76
  end
77
77
  end
78
- it { expect(output).to have_css 'div', :count => 1 }
79
- it { expect(output).to have_css 'a', :count => 1 }
78
+ it { expect(output).to have_css 'div', count: 1 }
79
+ it { expect(output).to have_css 'a', count: 1 }
80
80
  it { expect(output).to have_css 'div > a' }
81
- it { expect(output).to have_css 'div > a', :text => 'Hello' }
82
- it { expect(output).to have_css 'img', :count => 1 }
81
+ it { expect(output).to have_css 'div > a', text: 'Hello' }
82
+ it { expect(output).to have_css 'img', count: 1 }
83
83
  it { expect(output).to have_css 'div > a > img' }
84
84
  end
85
85
  end
@@ -94,9 +94,9 @@ describe 'markup helpers' do
94
94
  end
95
95
  end
96
96
 
97
- it { expect(output).to have_css 'ul', :count => 1 }
98
- it { expect(output).to have_css 'li', :count => 3 }
99
- it { expect(output).to have_css 'ul > li', :count => 3 }
97
+ it { expect(output).to have_css 'ul', count: 1 }
98
+ it { expect(output).to have_css 'li', count: 3 }
99
+ it { expect(output).to have_css 'ul > li', count: 3 }
100
100
  end
101
101
 
102
102
  describe 'concatenation with text' do
@@ -108,12 +108,12 @@ describe 'markup helpers' do
108
108
  end
109
109
  end
110
110
 
111
- it { expect(output).to have_css 'ul', :count => 1 }
112
- it { expect(output).to have_css 'li', :count => 3 }
113
- it { expect(output).to have_css 'ul > li', :count => 3 }
114
- it { expect(output).to have_css 'ul > li', :text => 'One' }
115
- it { expect(output).to have_css 'ul > li', :text => 'Two' }
116
- it { expect(output).to have_css 'ul > li', :text => 'Three' }
111
+ it { expect(output).to have_css 'ul', count: 1 }
112
+ it { expect(output).to have_css 'li', count: 3 }
113
+ it { expect(output).to have_css 'ul > li', count: 3 }
114
+ it { expect(output).to have_css 'ul > li', text: 'One' }
115
+ it { expect(output).to have_css 'ul > li', text: 'Two' }
116
+ it { expect(output).to have_css 'ul > li', text: 'Three' }
117
117
  end
118
118
 
119
119
  describe 'nested' do
@@ -125,13 +125,13 @@ describe 'markup helpers' do
125
125
  end
126
126
  end
127
127
 
128
- it { expect(output).to have_css 'ul', :count => 1 }
129
- it { expect(output).to have_css 'li', :count => 3 }
130
- it { expect(output).to have_css 'ul > li', :count => 3 }
131
- it { expect(output).to have_css 'a', :count => 3 }
132
- it { expect(output).to have_css 'ul > li > a', :text => 'One' }
133
- it { expect(output).to have_css 'ul > li > a', :text => 'Two' }
134
- it { expect(output).to have_css 'ul > li > a', :text => 'Three' }
128
+ it { expect(output).to have_css 'ul', count: 1 }
129
+ it { expect(output).to have_css 'li', count: 3 }
130
+ it { expect(output).to have_css 'ul > li', count: 3 }
131
+ it { expect(output).to have_css 'a', count: 3 }
132
+ it { expect(output).to have_css 'ul > li > a', text: 'One' }
133
+ it { expect(output).to have_css 'ul > li > a', text: 'Two' }
134
+ it { expect(output).to have_css 'ul > li > a', text: 'Three' }
135
135
  end
136
136
 
137
137
  describe 'outside content block' do
@@ -165,7 +165,7 @@ describe 'markup helpers' do
165
165
 
166
166
  it 'should buffer with newlines after text' do
167
167
  output = tag(:ul) do
168
- tag (:li) do
168
+ tag :li do
169
169
  text 'Hi'
170
170
  append! 'Hi'
171
171
  end
@@ -243,7 +243,7 @@ describe 'markup helpers' do
243
243
 
244
244
  describe 'content tags' do
245
245
  it 'should define content tags' do
246
- tags = %w(
246
+ tags = %w(
247
247
  article aside audio bdi canvas command datalist details
248
248
  figcaption figure header hgroup keygen mark meter nav output progress
249
249
  section source summary track video wbr a abbr address b bdo big
@@ -274,8 +274,8 @@ describe 'markup helpers' do
274
274
  end
275
275
 
276
276
  it { expect(output).to have_title "Tiny Page!" }
277
- it { expect(output).to have_css 'body', :count => 1 }
278
- it { expect(output).to have_css 'body > h1', :text => "Hello Tiny!", :count => 1 }
277
+ it { expect(output).to have_css 'body', count: 1 }
278
+ it { expect(output).to have_css 'body > h1', text: "Hello Tiny!", count: 1 }
279
279
  end
280
280
 
281
281
  describe 'dsl' do
@@ -284,25 +284,25 @@ describe 'markup helpers' do
284
284
  describe 'void tags' do
285
285
  Tiny::HTML.void_tags.each do |tag_name|
286
286
  it "should render '#{tag_name}'" do
287
- expect(self.send(tag_name)).to eq("<#{tag_name} />")
287
+ expect(send(tag_name)).to eq("<#{tag_name} />")
288
288
  end
289
289
  end
290
290
 
291
291
  it "should render attributes" do
292
- expect(link(:href => "some.css")).to eq('<link href="some.css" />')
292
+ expect(link(href: "some.css")).to eq('<link href="some.css" />')
293
293
  end
294
294
  end
295
295
 
296
296
  describe 'content tags' do
297
297
  Tiny::HTML.content_tags.each do |tag_name|
298
298
  it "should render '#{tag_name}'" do
299
- expect(self.send(tag_name)).to eq("<#{tag_name}></#{tag_name}>")
299
+ expect(send(tag_name)).to eq("<#{tag_name}></#{tag_name}>")
300
300
  end
301
301
  end
302
302
 
303
303
  it "should render content and attributes" do
304
- expect(h1(:class => 'main') { text "Hello" }).to eq(%{<h1 class="main">\n Hello\n</h1>})
305
- expect(h1("Hello", :class => 'main')).to eq(%{<h1 class="main">Hello</h1>})
304
+ expect(h1(class: 'main') { text "Hello" }).to eq(%(<h1 class="main">\n Hello\n</h1>))
305
+ expect(h1("Hello", class: 'main')).to eq(%(<h1 class="main">Hello</h1>))
306
306
  end
307
307
  end
308
308
  end
@@ -1,20 +1,20 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'markup helpers', :type => :request do
4
+ describe 'markup helpers', type: :request do
5
5
  include Tiny::Helpers
6
6
 
7
7
  let(:output) do
8
8
  Capybara::Node::Simple.new(@output)
9
9
  end
10
10
 
11
- def span &block
11
+ def span(&block)
12
12
  with_buffer do
13
13
  tag(:span, &block)
14
14
  end
15
15
  end
16
16
 
17
- def check_block &block
17
+ def check_block(&block)
18
18
  expect(erb_block?(block)).to be_truthy
19
19
  end
20
20
 
@@ -28,7 +28,7 @@ describe 'markup helpers', :type => :request do
28
28
 
29
29
  it 'should emit tag' do
30
30
  @output = Tilt['erb'].new { '<%= tag(:div) %>' }.render(self)
31
- expect(output).to have_css 'div', :count => 1
31
+ expect(output).to have_css 'div', count: 1
32
32
  end
33
33
 
34
34
  it 'should not buffer multiple tags' do
@@ -44,14 +44,14 @@ describe 'markup helpers', :type => :request do
44
44
  end
45
45
 
46
46
  it 'should concat erb block' do
47
- template = Tilt['erb'].new(:outvar => '@_out_buf') { '<%= span do %>Hello<% end %>' }
47
+ template = Tilt['erb'].new(outvar: '@_out_buf') { '<%= span do %>Hello<% end %>' }
48
48
  expect(template.render(self)).to eq("<span>\n Hello\n</span>\n")
49
49
  end
50
50
 
51
51
  describe 'block passing' do
52
52
  describe 'shallow' do
53
53
  before do
54
- @output = Tilt['erb'].new(:outvar => '@_out_buf') do
54
+ @output = Tilt['erb'].new(outvar: '@_out_buf') do
55
55
  <<-ERB
56
56
  <%= tag(:div) do %>
57
57
  <%= tag(:a) do %>
@@ -61,9 +61,9 @@ describe 'markup helpers', :type => :request do
61
61
  ERB
62
62
  end.render(self)
63
63
  end
64
- it { expect(output).to have_css 'div', :count => 1 }
65
- it { expect(output).to have_css 'a', :count => 1 }
66
- it { expect(output).to have_css 'div > a', :text => 'Hello' }
64
+ it { expect(output).to have_css 'div', count: 1 }
65
+ it { expect(output).to have_css 'a', count: 1 }
66
+ it { expect(output).to have_css 'div > a', text: 'Hello' }
67
67
  end
68
68
 
69
69
  describe 'nested' do
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'markup helpers', :type => :request do
4
+ describe 'markup helpers', type: :request do
5
5
  include Tiny::Helpers
6
6
 
7
7
  let(:output) do
@@ -11,7 +11,7 @@ describe 'markup helpers', :type => :request do
11
11
  describe 'tag' do
12
12
  it 'should emit tag' do
13
13
  @output = Tilt['haml'].new { '= tag(:div)' }.render(self)
14
- expect(output).to have_css 'div', :count => 1
14
+ expect(output).to have_css 'div', count: 1
15
15
  end
16
16
 
17
17
  it 'should emit haml block' do
@@ -21,7 +21,7 @@ describe 'markup helpers', :type => :request do
21
21
  Hello
22
22
  HAML
23
23
  end.render(self)
24
- expect(output).to have_css 'div', :text => "Hello", :count => 1
24
+ expect(output).to have_css 'div', text: "Hello", count: 1
25
25
  end
26
26
  end
27
27
 
@@ -36,9 +36,9 @@ describe 'markup helpers', :type => :request do
36
36
  HAML
37
37
  end.render(self)
38
38
  end
39
- it { expect(output).to have_css 'div', :count => 1 }
40
- it { expect(output).to have_css 'a', :count => 1 }
41
- it { expect(output).to have_css 'div > a', :text => 'Hello' }
39
+ it { expect(output).to have_css 'div', count: 1 }
40
+ it { expect(output).to have_css 'a', count: 1 }
41
+ it { expect(output).to have_css 'div > a', text: 'Hello' }
42
42
  end
43
43
 
44
44
  describe 'nested' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require "#{SUPPORT}/rails_app"
3
3
 
4
- describe 'Rails compatibility', :type => :request do
4
+ describe 'Rails compatibility', type: :request do
5
5
  include Rack::Test::Methods
6
6
 
7
7
  let(:output) do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require "#{SUPPORT}/sinatra_app"
3
3
 
4
- describe 'Sinatra compatibility', :type => :request do
4
+ describe 'Sinatra compatibility', type: :request do
5
5
  let(:output) do
6
6
  Capybara::Node::Simple.new(page.body)
7
7
  end
@@ -9,7 +9,7 @@ require 'haml'
9
9
  require 'sinatra'
10
10
  require 'tiny'
11
11
 
12
- $:.unshift File.dirname(__FILE__)
12
+ $LOAD_PATH.unshift File.dirname(__FILE__)
13
13
  require 'support/list_helper'
14
14
 
15
15
  RSpec.configure do |config|
@@ -21,39 +21,39 @@ FIXTURES = "#{File.dirname __FILE__}/fixtures"
21
21
  SUPPORT = "#{File.dirname __FILE__}/support"
22
22
 
23
23
  shared_examples_for 'it renders my list' do
24
- it { expect(output).to have_css 'ul', :count => 1 }
25
- it { expect(output).to have_css 'li', :count => 3 }
26
- it { expect(output).to have_css 'a', :count => 3 }
27
- it { expect(output).to have_css 'span', :count => 3 }
24
+ it { expect(output).to have_css 'ul', count: 1 }
25
+ it { expect(output).to have_css 'li', count: 3 }
26
+ it { expect(output).to have_css 'a', count: 3 }
27
+ it { expect(output).to have_css 'span', count: 3 }
28
28
  it { expect(output).to have_css 'ul > li' }
29
29
  it { expect(output).to have_css 'ul > li > a' }
30
- it { expect(output).to have_css 'ul > li > a', :text => 'A' }
31
- it { expect(output).to have_css 'ul > li > a > span', :text => '1' }
32
- it { expect(output).to have_css 'ul > li > a', :text => 'B' }
33
- it { expect(output).to have_css 'ul > li > a > span', :text => '2' }
34
- it { expect(output).to have_css 'ul > li > a', :text => 'C' }
35
- it { expect(output).to have_css 'ul > li > a > span', :text => '3' }
30
+ it { expect(output).to have_css 'ul > li > a', text: 'A' }
31
+ it { expect(output).to have_css 'ul > li > a > span', text: '1' }
32
+ it { expect(output).to have_css 'ul > li > a', text: 'B' }
33
+ it { expect(output).to have_css 'ul > li > a > span', text: '2' }
34
+ it { expect(output).to have_css 'ul > li > a', text: 'C' }
35
+ it { expect(output).to have_css 'ul > li > a > span', text: '3' }
36
36
  end
37
37
 
38
38
  shared_examples_for 'it renders my form' do
39
- it { expect(output).to have_css 'form', :count => 1 }
40
- it { expect(output).to have_css 'form[action="/login"]', :count => 1 }
41
- it { expect(output).to have_css 'form > fieldset', :count => 1 }
42
- it { expect(output).to have_css 'form > fieldset > label', :count => 1}
43
- it { expect(output).to have_css 'form > fieldset > label[for=email]', :text => 'Email', :count => 1}
44
- it { expect(output).to have_css 'form > fieldset > input', :count => 1}
45
- it { expect(output).to have_css 'form > fieldset > input#email[type=text][value="email@example.com"]', :count => 1 }
39
+ it { expect(output).to have_css 'form', count: 1 }
40
+ it { expect(output).to have_css 'form[action="/login"]', count: 1 }
41
+ it { expect(output).to have_css 'form > fieldset', count: 1 }
42
+ it { expect(output).to have_css 'form > fieldset > label', count: 1 }
43
+ it { expect(output).to have_css 'form > fieldset > label[for=email]', text: 'Email', count: 1 }
44
+ it { expect(output).to have_css 'form > fieldset > input', count: 1 }
45
+ it { expect(output).to have_css 'form > fieldset > input#email[type=text][value="email@example.com"]', count: 1 }
46
46
  end
47
47
 
48
48
  class Renderer
49
49
  include Tiny::Helpers
50
50
  include ListHelper
51
51
 
52
- def initialize template
52
+ def initialize(template)
53
53
  @template = template
54
54
  end
55
55
 
56
56
  def render
57
- Tilt.new("#{FIXTURES}/#{@template}", :outvar => '@output').render(self)
57
+ Tilt.new("#{FIXTURES}/#{@template}", outvar: '@output').render(self)
58
58
  end
59
59
  end
@@ -5,7 +5,7 @@ module FormHelper
5
5
  end
6
6
 
7
7
  def markup
8
- form(:action => @action) do
8
+ form(action: @action) do
9
9
  fieldset do
10
10
  yield(self)
11
11
  end
@@ -23,8 +23,8 @@ module FormHelper
23
23
  end
24
24
 
25
25
  def markup
26
- label(@name.capitalize, :for => @name)
27
- input(:type => 'text', :id => @name, :name => @name, :value => @value)
26
+ label(@name.capitalize, for: @name)
27
+ input(type: 'text', id: @name, name: @name, value: @value)
28
28
  end
29
29
  end
30
30
 
@@ -1,12 +1,12 @@
1
1
  module ListHelper
2
- def list &block
2
+ def list(&block)
3
3
  html_tag(:ul, &block)
4
4
  end
5
5
 
6
- def item_content num
6
+ def item_content(num)
7
7
  html_tag(:li) do
8
8
  html_tag(:a) do
9
- text (num + 64).chr
9
+ text((num + 64).chr)
10
10
  html_tag(:span) { text num }
11
11
  end
12
12
  end
@@ -5,8 +5,6 @@ ActionController::Base.view_paths = FIXTURES
5
5
 
6
6
  module RailsTestApp
7
7
  class Application < Rails::Application
8
- config.secret_token = '572c86f5ede338bd8aba8dae0fd3a326aabababc98d1e6ce34b9f5'
9
-
10
8
  routes.draw do
11
9
  get '/erb' => 'rails_test_app/test#erb'
12
10
  get '/erb_helpers' => 'rails_test_app/test#erb_helpers'
@@ -23,19 +21,19 @@ module RailsTestApp
23
21
  end
24
22
 
25
23
  def erb
26
- render :template => "erb_list"
24
+ render template: "erb_list"
27
25
  end
28
26
 
29
27
  def erb_helpers
30
- render :template => "erb_list_with_helpers"
28
+ render template: "erb_list_with_helpers"
31
29
  end
32
30
 
33
31
  def haml
34
- render :template => "haml_list"
32
+ render template: "haml_list"
35
33
  end
36
34
 
37
35
  def haml_helpers
38
- render :template => "haml_list_with_helpers"
36
+ render template: "haml_list_with_helpers"
39
37
  end
40
38
  end
41
39
  end
@@ -21,13 +21,15 @@ describe Tiny::Widget do
21
21
  end
22
22
 
23
23
  it 'should output content with block' do
24
- output = Class.new(Tiny::Widget) do
24
+ widget = Class.new(Tiny::Widget) do
25
25
  def markup
26
26
  append! "<div>"
27
27
  yield
28
28
  append! "</div>"
29
29
  end
30
- end.new.to_html { text 'Hello' }
30
+ end
31
+
32
+ output = widget.new.to_html { text 'Hello' }
31
33
  expect(output).to eq("<div>\nHello\n</div>\n")
32
34
  end
33
35
  end
@@ -45,21 +47,21 @@ describe Tiny::Widget do
45
47
  end
46
48
 
47
49
  it { expect(output).to have_title "Tiny Page!" }
48
- it { expect(output).to have_css 'body', :count => 1 }
49
- it { expect(output).to have_css 'body > h1', :text => "Hello Tiny!", :count => 1 }
50
+ it { expect(output).to have_css 'body', count: 1 }
51
+ it { expect(output).to have_css 'body > h1', text: "Hello Tiny!", count: 1 }
50
52
  end
51
53
 
52
54
  describe 'content from different methods' do
53
55
  before do
54
56
  @output = Class.new(Tiny::Widget) do
55
57
  def notices
56
- div :id => :notices do
58
+ div id: :notices do
57
59
  h1 'Notices'
58
60
  end
59
61
  end
60
62
 
61
63
  def main
62
- div :id => :content do
64
+ div id: :content do
63
65
  h1 "Content"
64
66
  end
65
67
  end
@@ -71,10 +73,10 @@ describe Tiny::Widget do
71
73
  end.new.to_html
72
74
  end
73
75
 
74
- it { expect(output).to have_css 'div#notices', :count => 1 }
75
- it { expect(output).to have_css 'div#notices > h1', :text => "Notices", :count => 1 }
76
- it { expect(output).to have_css 'div#content', :count => 1 }
77
- it { expect(output).to have_css 'div#content > h1', :text => "Content", :count => 1 }
76
+ it { expect(output).to have_css 'div#notices', count: 1 }
77
+ it { expect(output).to have_css 'div#notices > h1', text: "Notices", count: 1 }
78
+ it { expect(output).to have_css 'div#content', count: 1 }
79
+ it { expect(output).to have_css 'div#content > h1', text: "Content", count: 1 }
78
80
  end
79
81
 
80
82
  describe 'rendering a tag from outside' do
@@ -82,44 +84,44 @@ describe Tiny::Widget do
82
84
  @title = "Content" # no need to smuggle instance variables
83
85
  @output = Class.new(Tiny::Widget) do
84
86
  def markup
85
- div :id => :content do
87
+ div id: :content do
86
88
  yield
87
89
  end
88
90
  end
89
91
  end.new.to_html { tag :h1, @title }
90
92
  end
91
93
 
92
- it { expect(output).to have_css 'div#content', :count => 1 }
93
- it { expect(output).to have_css 'div#content > h1', :text => "Content", :count => 1 }
94
+ it { expect(output).to have_css 'div#content', count: 1 }
95
+ it { expect(output).to have_css 'div#content > h1', text: "Content", count: 1 }
94
96
  end
95
97
 
96
98
  describe 'rendering a block from outside with concatenated tags' do
97
99
  before do
98
100
  @output = Class.new(Tiny::Widget) do
99
- def markup &block
100
- div(:id => :content, &block)
101
+ def markup(&block)
102
+ div(id: :content, &block)
101
103
  end
102
104
  end.new.to_html { tag(:h1, "Title"); tag(:p, "Content") }
103
105
  end
104
106
 
105
- it { expect(output).to have_css 'div#content', :count => 1 }
106
- it { expect(output).to have_css 'div#content > h1', :text => "Title", :count => 1 }
107
- it { expect(output).to have_css 'div#content > p', :text => "Content", :count => 1 }
107
+ it { expect(output).to have_css 'div#content', count: 1 }
108
+ it { expect(output).to have_css 'div#content > h1', text: "Title", count: 1 }
109
+ it { expect(output).to have_css 'div#content > p', text: "Content", count: 1 }
108
110
  end
109
111
 
110
112
  describe 'rendering an erb block' do
111
113
  before do
112
114
  widget = Class.new(Tiny::Widget) do
113
- def markup &block
114
- div(:id => :content, &block)
115
+ def markup(&block)
116
+ div(id: :content, &block)
115
117
  end
116
118
  end.new
117
- @output = Tilt['erb'].new { '<%= widget.to_html do %><h1>Title</h1><p>Content</p><% end %>' }.render(self, :widget => widget)
119
+ @output = Tilt['erb'].new { '<%= widget.to_html do %><h1>Title</h1><p>Content</p><% end %>' }.render(self, widget: widget)
118
120
  end
119
121
 
120
- it { expect(output).to have_css 'div#content', :count => 1 }
121
- it { expect(output).to have_css 'div#content > h1', :text => "Title", :count => 1 }
122
- it { expect(output).to have_css 'div#content > p', :text => "Content", :count => 1 }
122
+ it { expect(output).to have_css 'div#content', count: 1 }
123
+ it { expect(output).to have_css 'div#content > h1', text: "Title", count: 1 }
124
+ it { expect(output).to have_css 'div#content > p', text: "Content", count: 1 }
123
125
  end
124
126
 
125
127
  describe 'widget with no content overriden' do
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
3
  require "tiny/version"
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -7,9 +7,9 @@ Gem::Specification.new do |s|
7
7
  s.version = Tiny::VERSION
8
8
  s.authors = ["Macario"]
9
9
  s.email = ["macarui@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{Framework agnostic markup builder, useful for building view helpers or as a micro templating dsl, plays nice with erb and haml}
12
- s.description = %q{Tiny is a tiny framework agnostic markup builder, useful for building view helpers on inclusion only adds three public methods, tag (for generating html tags), capture and concat, works as pure ruby and with erb and haml}
10
+ s.homepage = "https://github.com/maca/tiny"
11
+ s.summary = 'Framework agnostic markup builder, useful for building view helpers or as a micro templating dsl, plays nice with erb and haml'
12
+ s.description = 'Tiny is a tiny framework agnostic markup builder, useful for building view helpers on inclusion only adds three public methods, tag (for generating html tags), capture and concat, works as pure ruby and with erb and haml'
13
13
 
14
14
  s.rubyforge_project = "tiny"
15
15
 
@@ -21,9 +21,9 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency 'tilt'
22
22
  s.add_runtime_dependency 'erubis'
23
23
 
24
- s.add_development_dependency 'rspec', '~> 3.1.0'
25
- s.add_development_dependency 'capybara', '~> 2.4.0'
26
- s.add_development_dependency 'haml', '~> 3.1'
27
- s.add_development_dependency 'sinatra'
28
- s.add_development_dependency 'rails', '~> 4.1.0'
24
+ s.add_development_dependency 'rspec', '~> 3.7.0'
25
+ s.add_development_dependency 'capybara', '~> 3.2.1'
26
+ s.add_development_dependency 'haml', '~> 5.0.4'
27
+ s.add_development_dependency 'sinatra', '~> 2.0.3'
28
+ s.add_development_dependency 'rails', '~> 5.2.0'
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Macario
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-06 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tilt
@@ -44,70 +44,70 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.0
47
+ version: 3.7.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
- version: 3.1.0
54
+ version: 3.7.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: capybara
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.4.0
61
+ version: 3.2.1
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
- version: 2.4.0
68
+ version: 3.2.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: haml
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.1'
75
+ version: 5.0.4
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
- version: '3.1'
82
+ version: 5.0.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sinatra
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 2.0.3
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
- version: '0'
96
+ version: 2.0.3
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rails
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 4.1.0
103
+ version: 5.2.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
- version: 4.1.0
110
+ version: 5.2.0
111
111
  description: Tiny is a tiny framework agnostic markup builder, useful for building
112
112
  view helpers on inclusion only adds three public methods, tag (for generating html
113
113
  tags), capture and concat, works as pure ruby and with erb and haml
@@ -145,7 +145,7 @@ files:
145
145
  - spec/support/sinatra_app.rb
146
146
  - spec/widget_spec.rb
147
147
  - tiny.gemspec
148
- homepage: ''
148
+ homepage: https://github.com/maca/tiny
149
149
  licenses: []
150
150
  metadata: {}
151
151
  post_install_message:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  requirements: []
166
166
  rubyforge_project: tiny
167
- rubygems_version: 2.2.2
167
+ rubygems_version: 2.7.3
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: Framework agnostic markup builder, useful for building view helpers or as
@@ -186,4 +186,3 @@ test_files:
186
186
  - spec/support/rails_app.rb
187
187
  - spec/support/sinatra_app.rb
188
188
  - spec/widget_spec.rb
189
- has_rdoc: