garterbelt 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ = Version 0.1.1
2
+ * Bug fix: textarea tags should not have pretty formatting, because white space ends up in the text area
data/TODO CHANGED
@@ -13,6 +13,7 @@ view
13
13
  renderers
14
14
  switch from erb to direct escaping of text
15
15
  make quotes not escape
16
+ handle funky chars, html entities, re-escaping
16
17
 
17
18
  page
18
19
  embed_js, embed_css file content, string content
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{garterbelt}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kane Baccigalupi"]
12
- s.date = %q{2011-04-19}
12
+ s.date = %q{2011-04-20}
13
13
  s.description = %q{Garterbelt is a Ruby HTML/XML markup framework inspired by Erector and Markaby. Garterbelt maps html tags to methods allowing the intuitive construction of HTML pages using nothing but Ruby. And because it is all Ruby all the time, views benefit from the dryness of inheritance, modules and all the meta magic that Ruby can imagine. Stockings not included.}
14
14
  s.email = %q{baccigalupi@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.files = [
21
21
  ".document",
22
22
  ".rspec",
23
+ "CHANGELOG",
23
24
  "Gemfile",
24
25
  "Gemfile.lock",
25
26
  "LICENSE.txt",
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
43
44
  "lib/support/string.rb",
44
45
  "lib/view.rb",
45
46
  "spec/garterbelt_spec.rb",
47
+ "spec/integration/expectations/form_with_textarea.html",
46
48
  "spec/integration/expectations/general_view.html",
47
49
  "spec/integration/expectations/render_styles/compact.html",
48
50
  "spec/integration/expectations/render_styles/minified.html",
@@ -56,6 +58,7 @@ Gem::Specification.new do |s|
56
58
  "spec/integration/expectations/view_with_tags.html",
57
59
  "spec/integration/integration_spec.rb",
58
60
  "spec/integration/templates/form.rb",
61
+ "spec/integration/templates/form_with_textarea.rb",
59
62
  "spec/integration/templates/pretty_with_embeds.rb",
60
63
  "spec/integration/templates/unescaping_view.rb",
61
64
  "spec/integration/templates/view_partial_nest.rb",
@@ -69,6 +72,7 @@ Gem::Specification.new do |s|
69
72
  "spec/performance/profiling.rb",
70
73
  "spec/performance/templates/erector.rb",
71
74
  "spec/performance/templates/garterbelt.rb",
75
+ "spec/performance/templates/ham.haml",
72
76
  "spec/performance/vs_erector.rb",
73
77
  "spec/renderers/cache_spec.rb",
74
78
  "spec/renderers/closed_tag_spec.rb",
@@ -80,6 +84,7 @@ Gem::Specification.new do |s|
80
84
  "spec/string_spec.rb",
81
85
  "spec/support/mock_view.rb",
82
86
  "spec/support/puters.rb",
87
+ "spec/view/anonymous_view_spec.rb",
83
88
  "spec/view/view_basics_spec.rb",
84
89
  "spec/view/view_caching_spec.rb",
85
90
  "spec/view/view_partial_spec.rb",
@@ -96,6 +101,7 @@ Gem::Specification.new do |s|
96
101
  "spec/garterbelt_spec.rb",
97
102
  "spec/integration/integration_spec.rb",
98
103
  "spec/integration/templates/form.rb",
104
+ "spec/integration/templates/form_with_textarea.rb",
99
105
  "spec/integration/templates/pretty_with_embeds.rb",
100
106
  "spec/integration/templates/unescaping_view.rb",
101
107
  "spec/integration/templates/view_partial_nest.rb",
@@ -120,6 +126,7 @@ Gem::Specification.new do |s|
120
126
  "spec/string_spec.rb",
121
127
  "spec/support/mock_view.rb",
122
128
  "spec/support/puters.rb",
129
+ "spec/view/anonymous_view_spec.rb",
123
130
  "spec/view/view_basics_spec.rb",
124
131
  "spec/view/view_caching_spec.rb",
125
132
  "spec/view/view_partial_spec.rb",
@@ -5,7 +5,7 @@ module Garterbelt
5
5
  end
6
6
 
7
7
  def template
8
- view.render_style == :text ? "" : "#{indent}<!-- #{content} -->#{line_end}"
8
+ style == :text ? "" : "#{indent}<!-- #{content} -->#{line_end}"
9
9
  end
10
10
 
11
11
  def render
@@ -2,7 +2,7 @@ module Garterbelt
2
2
  module ContentRendering
3
3
  def self.included(base)
4
4
  base.class_eval <<-RUBY
5
- attr_accessor :content
5
+ attr_accessor :content, :view_escape, :view_style
6
6
 
7
7
  include InstanceMethods
8
8
  RUBY
@@ -17,10 +17,17 @@ module Garterbelt
17
17
  end
18
18
 
19
19
  def head
20
+ self.view_style = view.render_style
21
+ self.view_escape = view._escape
22
+
23
+ view.render_style = style
24
+ view._escape = escape
20
25
  view._level += 1
21
26
  end
22
27
 
23
28
  def foot
29
+ view.render_style = view_style
30
+ view._escape = view_escape
24
31
  view._level -= 1
25
32
  end
26
33
 
@@ -24,7 +24,12 @@ module Garterbelt
24
24
  end
25
25
 
26
26
  def head_template
27
- style == :text ? '' : "#{indent}<#{type}#{rendered_attributes}>#{line_end}"
27
+ if style == :text
28
+ ''
29
+ else
30
+ head_end = style == :compact ? '' : line_end
31
+ "#{indent}<#{type}#{rendered_attributes}>#{head_end}"
32
+ end
28
33
  end
29
34
 
30
35
  def head
@@ -36,7 +41,8 @@ module Garterbelt
36
41
  if style == :text
37
42
  [:p, :ul, :ol, :li].include?(type) ? "\n" : ''
38
43
  else
39
- "#{indent}</#{type}>#{line_end}"
44
+ foot_dent = style == :compact ? '' : indent
45
+ "#{foot_dent}</#{type}>#{line_end}"
40
46
  end
41
47
  end
42
48
 
@@ -1,9 +1,12 @@
1
1
  module Garterbelt
2
2
  class Renderer
3
- attr_accessor :view
3
+ attr_accessor :view, :escape
4
+ attr_writer :style
4
5
 
5
6
  def initialize(opts)
6
7
  self.view = opts[:view] || raise(ArgumentError, ":view required in initialization options")
8
+ self.style = opts.delete(:render_style)
9
+ self.escape = view._escape
7
10
  end
8
11
 
9
12
  # Rendering -----------------------------------------------
@@ -20,7 +23,7 @@ module Garterbelt
20
23
  end
21
24
 
22
25
  def style
23
- view.render_style
26
+ @style ||= view.render_style
24
27
  end
25
28
 
26
29
  def indent
@@ -1,11 +1,10 @@
1
1
  module Garterbelt
2
2
  class Text < Renderer
3
- attr_accessor :content, :escape
3
+ attr_accessor :content
4
4
 
5
5
  def initialize(opts)
6
6
  super
7
7
  self.content = opts[:content] || ''
8
- self.escape = view._escape
9
8
  end
10
9
 
11
10
  def raise_with_block_content
@@ -31,6 +30,10 @@ module Garterbelt
31
30
  end
32
31
  end
33
32
 
33
+ def line_end
34
+ style == :compact ? '' : super
35
+ end
36
+
34
37
  def template
35
38
  "#{escaped_content}#{line_end}"
36
39
  end
@@ -142,6 +142,17 @@ module Garterbelt
142
142
  end
143
143
  end
144
144
 
145
+ def compact_tag(type, *args, &block)
146
+ args << {} unless args.last.is_a?(Hash)
147
+ args.last[:render_style] = :compact
148
+
149
+ if block_given?
150
+ tag(type, *args, &block)
151
+ else
152
+ tag(type, *args)
153
+ end
154
+ end
155
+
145
156
  def text(content)
146
157
  add_to_buffer Text.new(:view => _curator, :content => content)
147
158
  end
@@ -186,6 +197,7 @@ module Garterbelt
186
197
  opts[:content] = args.first
187
198
  end
188
199
  end
200
+ opts[:render_style] = opts[:attributes].delete(:render_style) if opts[:attributes] && opts[:attributes][:render_style]
189
201
  opts
190
202
  end
191
203
 
@@ -203,7 +215,7 @@ module Garterbelt
203
215
  'q', 's',
204
216
  'samp', 'select', 'small', 'span',
205
217
  'strong', 'sub', 'sup',
206
- 'table', 'tbody', 'td', 'textarea', 'tfoot',
218
+ 'table', 'tbody', 'td', 'tfoot',
207
219
  'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var'
208
220
  ]
209
221
  CONTENT_TAGS.each do |type|
@@ -241,6 +253,15 @@ module Garterbelt
241
253
  RUBY
242
254
  end
243
255
 
256
+ MINIFIED_TAGS = ['textarea']
257
+ MINIFIED_TAGS.each do |type|
258
+ class_eval <<-RUBY
259
+ def #{type}(*args, &block)
260
+ block_given? ? compact_tag(:#{type}, *args, &block) : compact_tag(:#{type}, *args)
261
+ end
262
+ RUBY
263
+ end
264
+
244
265
  def page_title(*args, &block)
245
266
  block_given? ? tag(:title, *args, &block) : tag(:title, *args)
246
267
  end
@@ -0,0 +1,3 @@
1
+ <form class="texty" action="/go/textarea" method="get">
2
+ <textarea name="my_text_area">foo</textarea>
3
+ </form>
@@ -16,6 +16,10 @@ describe Garterbelt::View, "Integration" do
16
16
  UnescapingView.new(:format_text => format_text).render.should == file('unescaping_view')
17
17
  end
18
18
 
19
+ it 'deals with textarea correctly' do
20
+ FormWithTextarea.new.render.should == file('form_with_textarea')
21
+ end
22
+
19
23
  describe 'variables' do
20
24
  it 'calls methods on passed objects' do
21
25
  user = Hashie::Mash.new(:email => 'foo@example.com')
@@ -0,0 +1,9 @@
1
+ class FormWithTextarea < Garterbelt::View
2
+ def content
3
+ partial FormView, :class => 'texty', :action => '/go/textarea' do
4
+ textarea :name => 'my_text_area' do
5
+ text 'foo'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ %html
2
+ %head
3
+ %title Benchmarking Templates
4
+ %link{"rel" => "stylesheet", :href => "/stylesheet/application.css"}
5
+ %link{"rel" => "stylesheet", :href => "/stylesheet/ie.css"}
6
+ %body.not_applicable
7
+ #wrapper.line
8
+ - if flash
9
+ #flash.inner
10
+ = flash
11
+ %dl{'class' => 'inner user_info'}
12
+ %dt username
13
+ %dd
14
+ = user.username
15
+ %dt email
16
+ %dd
17
+ = user.email
18
+ %dt name
19
+ %dd
20
+ = user.name
21
+ %dt number of assigned tasks
22
+ %dd
23
+ = rand(20)
@@ -5,27 +5,37 @@ require "rbench"
5
5
  require 'hashie'
6
6
 
7
7
  require 'erector'
8
+ require 'haml'
9
+
8
10
  require File.dirname(__FILE__) + "/../../lib/garterbelt"
9
11
 
10
12
  require File.dirname(__FILE__) + '/templates/garterbelt'
11
13
  require File.dirname(__FILE__) + '/templates/erector'
14
+ haml = File.read(File.dirname(__FILE__) + '/templates/ham.haml')
12
15
 
13
- TIMES = 500_000
16
+ TIMES = 10_000
14
17
 
15
18
  RBench.run(TIMES) do
16
19
  column :garterbelt
17
20
  column :erector
21
+ column :haml
18
22
 
19
23
  user = Hashie::Mash.new(:username => 'baccigalupi', :email => 'baccigalupi@example.com', :name => 'Kane Baccigalupi')
20
24
 
21
25
  report "Simple Page Initializing" do
22
26
  garterbelt { GarterbeltTemplate.new(:user => user) }
23
27
  erector { ErectorTemplate.new(:user => user) }
28
+ haml { Haml::Engine.new( haml ) }
24
29
  end
25
30
 
31
+ object = Object.new
32
+ object.instance_variable_set "@user", user
33
+ object.instance_variable_set "@flash", nil
34
+
26
35
  report "Simple Page Rendering" do
27
36
  garterbelt { GarterbeltTemplate.new(:user => user).render }
28
37
  erector { ErectorTemplate.new(:user => user).to_html }
38
+ haml { Haml::Engine.new( haml ).to_html(object, {:user => user, :flash => nil} ) }
29
39
  end
30
40
  end
31
41
 
@@ -167,7 +167,7 @@ describe Garterbelt::ClosedTag do
167
167
 
168
168
  describe ':minified' do
169
169
  before do
170
- @view.render_style = :minified
170
+ @tag.style = :minified
171
171
  @min = @tag.render
172
172
  end
173
173
 
@@ -183,7 +183,7 @@ describe Garterbelt::ClosedTag do
183
183
 
184
184
  describe ':text' do
185
185
  it 'is an empty string' do
186
- @view.render_style = :text
186
+ @tag.style = :text
187
187
  @tag.render.should == ''
188
188
  end
189
189
  end
@@ -67,7 +67,7 @@ describe Garterbelt::Comment do
67
67
 
68
68
  describe ':minified' do
69
69
  before do
70
- @view.render_style = :minified
70
+ @tag.style = :minified
71
71
  @min = @tag.render
72
72
  end
73
73
 
@@ -83,7 +83,7 @@ describe Garterbelt::Comment do
83
83
 
84
84
  describe ':text' do
85
85
  it 'is an empty string' do
86
- @view.render_style = :text
86
+ @tag.style = :text
87
87
  @tag.render.should == ''
88
88
  end
89
89
  end
@@ -123,6 +123,43 @@ describe Garterbelt::ContentTag do
123
123
  @tag.render.should_not match /\n/
124
124
  end
125
125
  end
126
+
127
+ describe ':compact' do
128
+ describe 'with block content' do
129
+ it 'is just like pretty' do
130
+ @tag.content = lambda { 'foo' }
131
+ @tag.style = :pretty
132
+ pretty = @tag.render
133
+ @tag.style = :compact
134
+ @tag.render.should == pretty
135
+ end
136
+ end
137
+
138
+ describe 'with string content' do
139
+ before do
140
+ @tag.content = "stringy"
141
+ @tag.style = :compact
142
+ @compact = @tag.render
143
+ end
144
+
145
+ it 'head tag does not end in a break' do
146
+ @compact.should match /<p[^>]*>/
147
+ @compact.should_not match /<p[^>]*>\n/
148
+ end
149
+
150
+ it 'tail tag does not have any indentation' do
151
+ @compact.should_not match />\s{1,50}<\/p>/
152
+ end
153
+ end
154
+ end
155
+
156
+ describe 'on initialization' do
157
+ it 'uses the value passed in over the view render style' do
158
+ @view.render_style = :pretty
159
+ tag = ContentTag.new(@params.merge(:render_style => :minified, :content => 'my great content'))
160
+ tag.style.should == :minified
161
+ end
162
+ end
126
163
  end
127
164
 
128
165
  describe 'content' do
@@ -77,7 +77,7 @@ describe Garterbelt::Text do
77
77
 
78
78
  describe ':minified' do
79
79
  before do
80
- @view.render_style = :minified
80
+ @tag.style = :minified
81
81
  @minified = @tag.render
82
82
  end
83
83
 
@@ -93,7 +93,7 @@ describe Garterbelt::Text do
93
93
 
94
94
  describe ':text' do
95
95
  before do
96
- @view.render_style = :text
96
+ @tag.style = :text
97
97
  @text = @tag.render
98
98
  end
99
99
 
@@ -105,6 +105,18 @@ describe Garterbelt::Text do
105
105
  @text.should_not match /\n1/
106
106
  end
107
107
  end
108
+
109
+ describe 'compact' do
110
+ before do
111
+ @tag.style = :compact
112
+ @compact = @tag.render
113
+ end
114
+
115
+ it 'is just the string' do
116
+ @compact.should == @str
117
+ end
118
+ end
119
+
108
120
  end
109
121
  end
110
122
  end
File without changes
@@ -273,6 +273,30 @@ describe Garterbelt::View do
273
273
  end
274
274
  end
275
275
 
276
+ describe '#compact_tag' do
277
+ it 'should call #tag' do
278
+ @view.should_receive(:tag)
279
+ @view.compact_tag(:textarea, "", {:class => 'classy'})
280
+ end
281
+
282
+ it 'passes in the :render_style option with :minified to tag' do
283
+ @view.should_receive(:tag).with(:textarea, "", {:render_style => :compact})
284
+ @view.compact_tag(:textarea, "")
285
+ end
286
+
287
+ it 'passes in the :render_style option with :minified when not receiving content arguments' do
288
+ @view.should_receive(:tag).with(:textarea, {:render_style => :compact, :class => :foo})
289
+ @view.compact_tag(:textarea, :class => :foo)
290
+ end
291
+
292
+ it 'content tag should be created with the correct attributes' do
293
+ @view.compact_tag(:textarea, :class => 'foo')
294
+ tag = @view._buffer.last
295
+ tag.style.should == :compact
296
+ tag.attributes.keys.should_not include :render_style
297
+ end
298
+ end
299
+
276
300
  describe '#text' do
277
301
  it 'makes a new Text' do
278
302
  Garterbelt::Text.should_receive(:new).and_return('some content')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garterbelt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kane Baccigalupi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-19 00:00:00 -07:00
18
+ date: 2011-04-20 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -217,6 +217,7 @@ extra_rdoc_files:
217
217
  files:
218
218
  - .document
219
219
  - .rspec
220
+ - CHANGELOG
220
221
  - Gemfile
221
222
  - Gemfile.lock
222
223
  - LICENSE.txt
@@ -240,6 +241,7 @@ files:
240
241
  - lib/support/string.rb
241
242
  - lib/view.rb
242
243
  - spec/garterbelt_spec.rb
244
+ - spec/integration/expectations/form_with_textarea.html
243
245
  - spec/integration/expectations/general_view.html
244
246
  - spec/integration/expectations/render_styles/compact.html
245
247
  - spec/integration/expectations/render_styles/minified.html
@@ -253,6 +255,7 @@ files:
253
255
  - spec/integration/expectations/view_with_tags.html
254
256
  - spec/integration/integration_spec.rb
255
257
  - spec/integration/templates/form.rb
258
+ - spec/integration/templates/form_with_textarea.rb
256
259
  - spec/integration/templates/pretty_with_embeds.rb
257
260
  - spec/integration/templates/unescaping_view.rb
258
261
  - spec/integration/templates/view_partial_nest.rb
@@ -266,6 +269,7 @@ files:
266
269
  - spec/performance/profiling.rb
267
270
  - spec/performance/templates/erector.rb
268
271
  - spec/performance/templates/garterbelt.rb
272
+ - spec/performance/templates/ham.haml
269
273
  - spec/performance/vs_erector.rb
270
274
  - spec/renderers/cache_spec.rb
271
275
  - spec/renderers/closed_tag_spec.rb
@@ -277,6 +281,7 @@ files:
277
281
  - spec/string_spec.rb
278
282
  - spec/support/mock_view.rb
279
283
  - spec/support/puters.rb
284
+ - spec/view/anonymous_view_spec.rb
280
285
  - spec/view/view_basics_spec.rb
281
286
  - spec/view/view_caching_spec.rb
282
287
  - spec/view/view_partial_spec.rb
@@ -321,6 +326,7 @@ test_files:
321
326
  - spec/garterbelt_spec.rb
322
327
  - spec/integration/integration_spec.rb
323
328
  - spec/integration/templates/form.rb
329
+ - spec/integration/templates/form_with_textarea.rb
324
330
  - spec/integration/templates/pretty_with_embeds.rb
325
331
  - spec/integration/templates/unescaping_view.rb
326
332
  - spec/integration/templates/view_partial_nest.rb
@@ -345,6 +351,7 @@ test_files:
345
351
  - spec/string_spec.rb
346
352
  - spec/support/mock_view.rb
347
353
  - spec/support/puters.rb
354
+ - spec/view/anonymous_view_spec.rb
348
355
  - spec/view/view_basics_spec.rb
349
356
  - spec/view/view_caching_spec.rb
350
357
  - spec/view/view_partial_spec.rb