sinatra_more 0.1.0 → 0.1.1

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.
data/README.rdoc CHANGED
@@ -142,7 +142,7 @@ A form_tag might look like:
142
142
  - field_set_tag(:class => 'buttons') do
143
143
  = submit_tag "Login"
144
144
 
145
- ==== FormBuilders ====
145
+ ==== FormBuilders
146
146
 
147
147
  * form_for(object, url, settings={}, &block)
148
148
  * Constructs a form using given or default form_builder
@@ -266,7 +266,8 @@ provided to make interacting with warden dead simple.
266
266
 
267
267
  == Acknowledgements
268
268
 
269
- Thanks to keldredd for the sinatra-helpers code that helped me to create erb capture and concat methods!
269
+ Thanks to keldredd for the sinatra_helpers code that helped me to create erb capture and concat methods.
270
+ Thanks to sbfaulkner for the sinatra-helpers code that I looked over while building a few helper methods.
270
271
 
271
272
  == Contributers
272
273
 
data/TODO CHANGED
@@ -4,11 +4,23 @@
4
4
  * Make warden password strategy support a callback which explains what to do with username, password
5
5
  * WardenPlugin.authenticate_callback { |username, password| User.authenticate(username, password) }
6
6
  * Remove dependency on activesupport! and enumerate dependencies in rakefile
7
+ * Look into creating sinatra generators using rubigen (http://github.com/drnic/rubigen)
8
+ * http://github.com/quirkey/sinatra-gen
9
+ * Look into adding any missing helpers from:
10
+ * http://github.com/sbfaulkner/sinatra-helpers/tree/master/lib/sinatra-helpers/haml/
11
+ * http://github.com/sbfaulkner/sinatra-helpers/blob/master/lib/sinatra-helpers/html/escape.rb
12
+ * http://github.com/sbfaulkner/sinatra-helpers/blob/master/lib/sinatra-helpers/haml/links.rb
13
+ * http://github.com/kelredd/sinatra-helpers/tree/master/lib/sinatra_helpers/mailer/
14
+ * http://github.com/kelredd/sinatra-helpers/blob/master/lib/sinatra_helpers/erb/links.rb
15
+ * http://github.com/kelredd/sinatra-helpers/blob/master/lib/sinatra_helpers/erb/forms.rb
7
16
 
8
17
  = COMPLETED
9
18
 
10
19
  * Pull from sinatra-helpers and make erb templates work (and credit keldredd)
11
- - http://github.com/kelredd/sinatra-helpers/tree/master/lib/sinatra_helpers/erb/
20
+ * http://github.com/kelredd/sinatra-helpers/tree/master/lib/sinatra_helpers/erb/
12
21
  * fix content_block_tag to eliminate need for concat option
13
22
  * image_tag should start in images_path (or /images)
14
- * I have got to add tests, basically create dummy sinatra applications and use Webrat
23
+ * I have got to add tests, basically create dummy sinatra applications and use Webrat
24
+ * Partials with counter (and add to tests)
25
+ * http://github.com/sbfaulkner/sinatra-helpers/blob/master/lib/sinatra-helpers/haml/partials.rb
26
+ * http://github.com/kelredd/sinatra-helpers/blob/master/lib/sinatra_helpers/erb/partials.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -23,21 +23,24 @@ module SinatraMore
23
23
  # Partials implementation which includes collections support
24
24
  # partial 'photo/_item', :object => @photo
25
25
  # partial 'photo/_item', :collection => @photos
26
- def partial(template, *args)
27
- options = args.extract_options!
26
+ def partial(template, options={})
28
27
  options.merge!(:layout => false)
29
28
  path = template.to_s.split(File::SEPARATOR)
30
29
  object_name = path[-1].to_sym
31
30
  path[-1] = "_#{path[-1]}"
32
31
  template_path = File.join(path)
32
+ raise 'Partial collection specified but is nil' if options.has_key?(:collection) && options[:collection].nil?
33
33
  if collection = options.delete(:collection)
34
+ counter = 0
34
35
  collection.inject([]) do |buffer, member|
35
- collection_options = options.merge(:layout => false, :locals => { object_name => member })
36
- buffer << render_template(template_path, collection_options)
36
+ counter += 1
37
+ current_options = options.merge(:locals => { object_name => member, "#{object_name}_counter".to_sym => counter })
38
+ buffer << render_template(template_path, current_options)
37
39
  end.join("\n")
38
- elsif object_record = options.delete(:object)
39
- render_template(template_path, options.merge(:locals => { object_name => object_record }))
40
40
  else
41
+ if member = options.delete(:object)
42
+ options.merge!(:locals => {object_name => member})
43
+ end
41
44
  render_template(template_path, options)
42
45
  end
43
46
  end
@@ -48,7 +51,7 @@ module SinatraMore
48
51
  # Returns the template engine (i.e haml) to use for a given template_path
49
52
  # resolve_template_engine('users/new') => :haml
50
53
  def resolve_template_engine(template_path)
51
- resolved_template_path = File.join(self.options.views, template_path + ".*")
54
+ resolved_template_path = File.join(self.options.views, template_path.to_s + ".*")
52
55
  template_file = Dir[resolved_template_path].first
53
56
  raise "Template path '#{template_path}' could not be located in views!" unless template_file
54
57
  template_engine = File.extname(template_file)[1..-1].to_sym
data/sinatra_more.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_more}
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 = ["Nathan Esquenazi"]
@@ -60,7 +60,6 @@ Gem::Specification.new do |s|
60
60
  "test/markup_plugin/test_format_helpers.rb",
61
61
  "test/markup_plugin/test_output_helpers.rb",
62
62
  "test/markup_plugin/test_tag_helpers.rb",
63
- "test/test_markup_plugin.rb",
64
63
  "test/test_render_plugin.rb",
65
64
  "test/test_warden_plugin.rb"
66
65
  ]
@@ -80,7 +79,6 @@ Gem::Specification.new do |s|
80
79
  "test/markup_plugin/test_format_helpers.rb",
81
80
  "test/markup_plugin/test_output_helpers.rb",
82
81
  "test/markup_plugin/test_tag_helpers.rb",
83
- "test/test_markup_plugin.rb",
84
82
  "test/test_render_plugin.rb",
85
83
  "test/test_warden_plugin.rb"
86
84
  ]
@@ -1 +1,4 @@
1
- %h1 User name is #{user.name}
1
+ %h1 User name is #{user.name}
2
+
3
+ - if defined?(user_counter)
4
+ %p My counter is #{user_counter}
data/test/helper.rb CHANGED
@@ -10,6 +10,8 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
10
  require 'sinatra_more'
11
11
 
12
12
  class Test::Unit::TestCase
13
+ include SinatraMore::OutputHelpers
14
+ include SinatraMore::TagHelpers
13
15
  include Rack::Test::Methods
14
16
  include Webrat::Methods
15
17
  include Webrat::Matchers
@@ -1,12 +1,17 @@
1
- require 'test_markup_plugin' unless defined?(TestMarkupPlugin)
1
+ require 'helper'
2
+ require 'fixtures/markup_app/app'
2
3
 
3
- class TestAssetTagHelpers < TestMarkupPlugin
4
+ class TestAssetTagHelpers < Test::Unit::TestCase
4
5
  include SinatraMore::AssetTagHelpers
5
-
6
+
7
+ def app
8
+ MarkupDemo.tap { |app| app.set :environment, :test }
9
+ end
10
+
6
11
  def flash
7
- { :notice => "Demo notice" }
12
+ { :notice => "Demo notice" }
8
13
  end
9
-
14
+
10
15
  context 'for #flash_tag method' do
11
16
  should "display flash with no given attributes" do
12
17
  assert_equal '<div class="flash">Demo notice</div>', flash_tag(:notice)
@@ -16,7 +21,7 @@ class TestAssetTagHelpers < TestMarkupPlugin
16
21
  assert_equal flash_expected, flash_tag(:notice, :class => 'notice', :id => 'notice-area')
17
22
  end
18
23
  end
19
-
24
+
20
25
  context 'for #link_to method' do
21
26
  should "display link element with no given attributes" do
22
27
  assert_equal '<a href="/register">Sign up</a>', link_to('Sign up', '/register')
@@ -44,7 +49,7 @@ class TestAssetTagHelpers < TestMarkupPlugin
44
49
  # assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2'
45
50
  end
46
51
  end
47
-
52
+
48
53
  context 'for #image_tag method' do
49
54
  should "display image tag absolute link with no options" do
50
55
  assert_equal '<img src="/absolute/pic.gif" />', image_tag('/absolute/pic.gif')
@@ -56,7 +61,7 @@ class TestAssetTagHelpers < TestMarkupPlugin
56
61
  assert_equal '<img class="photo" src="/images/relative/pic.gif" />', image_tag(' relative/ pic.gif ', :class => 'photo')
57
62
  end
58
63
  end
59
-
64
+
60
65
  context 'for #stylesheet_link_tag method' do
61
66
  should "display stylesheet link item" do
62
67
  time = stop_time_for_test
@@ -71,7 +76,7 @@ class TestAssetTagHelpers < TestMarkupPlugin
71
76
  assert_equal expected_style, stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
72
77
  end
73
78
  end
74
-
79
+
75
80
  context 'for #javascript_include_tag method' do
76
81
  should "display javascript item" do
77
82
  time = stop_time_for_test
@@ -86,4 +91,4 @@ class TestAssetTagHelpers < TestMarkupPlugin
86
91
  assert_equal expected_include, javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
87
92
  end
88
93
  end
89
- end
94
+ end
@@ -1,5 +1,10 @@
1
- require 'test_markup_plugin' unless defined?(TestMarkupPlugin)
1
+ require 'helper'
2
+ require 'fixtures/markup_app/app'
3
+
4
+ class TestFormBuilder < Test::Unit::TestCase
5
+ def app
6
+ MarkupDemo.tap { |app| app.set :environment, :test }
7
+ end
2
8
 
3
- class TestFormBuilder < TestMarkupPlugin
4
9
  # TODO Test the form builder methods
5
- end
10
+ end
@@ -1,5 +1,10 @@
1
- require 'test_markup_plugin' unless defined?(TestMarkupPlugin)
1
+ require 'helper'
2
+ require 'fixtures/markup_app/app'
2
3
 
3
- class TestFormHelpers < TestMarkupPlugin
4
- # Test the form helper methods
5
- end
4
+ class TestFormHelpers < Test::Unit::TestCase
5
+ def app
6
+ MarkupDemo.tap { |app| app.set :environment, :test }
7
+ end
8
+
9
+ # Test the form helper methods
10
+ end
@@ -1,8 +1,13 @@
1
- require 'test_markup_plugin' unless defined?(TestMarkupPlugin)
1
+ require 'helper'
2
+ require 'fixtures/markup_app/app'
3
+
4
+ class TestFormatHelpers < Test::Unit::TestCase
5
+ def app
6
+ MarkupDemo.tap { |app| app.set :environment, :test }
7
+ end
2
8
 
3
- class TestFormatHelpers < TestMarkupPlugin
4
9
  include SinatraMore::FormatHelpers
5
-
10
+
6
11
  context 'for #relative_time_ago method' do
7
12
  should "display today" do
8
13
  assert_equal 'today', relative_time_ago(Time.now)
@@ -26,7 +31,7 @@ class TestFormatHelpers < TestMarkupPlugin
26
31
  assert_equal 500.days.ago.strftime('%A, %B %e, %Y'), relative_time_ago(500.days.ago)
27
32
  end
28
33
  end
29
-
34
+
30
35
  context 'for #escape_javascript method' do
31
36
  should "escape double quotes" do
32
37
  assert_equal "\"hello\"", escape_javascript('"hello"')
@@ -38,4 +43,4 @@ class TestFormatHelpers < TestMarkupPlugin
38
43
  assert_equal "\"\\n<p>hello<\\/p>\\n\"", escape_javascript("\n\r<p>hello</p>\r\n")
39
44
  end
40
45
  end
41
- end
46
+ end
@@ -1,32 +1,37 @@
1
- require 'test_markup_plugin' unless defined?(TestMarkupPlugin)
1
+ require 'helper'
2
+ require 'fixtures/markup_app/app'
3
+
4
+ class TestOutputHelpers < Test::Unit::TestCase
5
+ def app
6
+ MarkupDemo.tap { |app| app.set :environment, :test }
7
+ end
2
8
 
3
- class TestOutputHelpers < TestMarkupPlugin
4
9
  context 'for #capture_html method' do
5
10
  should "work for erb templates" do
6
11
  visit '/erb/capture_concat'
7
12
  assert_have_selector 'p span', :content => "Captured Line 1"
8
13
  assert_have_selector 'p span', :content => "Captured Line 2"
9
14
  end
10
-
15
+
11
16
  should "work for haml templates" do
12
17
  visit '/haml/capture_concat'
13
18
  assert_have_selector 'p span', :content => "Captured Line 1"
14
19
  assert_have_selector 'p span', :content => "Captured Line 2"
15
20
  end
16
21
  end
17
-
22
+
18
23
  context 'for #concat_content method' do
19
24
  should "work for erb templates" do
20
25
  visit '/erb/capture_concat'
21
26
  assert_have_selector 'p', :content => "Concat Line 3", :count => 1
22
27
  end
23
-
28
+
24
29
  should "work for haml templates" do
25
30
  visit '/haml/capture_concat'
26
31
  assert_have_selector 'p', :content => "Concat Line 3", :count => 1
27
- end
32
+ end
28
33
  end
29
-
34
+
30
35
  context 'for #block_is_template?' do
31
36
  should "work for erb templates" do
32
37
  visit '/erb/capture_concat'
@@ -34,11 +39,11 @@ class TestOutputHelpers < TestMarkupPlugin
34
39
  # assert_have_selector 'p', :content => "The erb block passed in is a template", :class => 'is_template'
35
40
  assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template'
36
41
  end
37
-
42
+
38
43
  should "work for haml templates" do
39
44
  visit '/haml/capture_concat'
40
45
  assert_have_selector 'p', :content => "The haml block passed in is a template", :class => 'is_template'
41
46
  assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template'
42
- end
47
+ end
43
48
  end
44
- end
49
+ end
@@ -1,9 +1,14 @@
1
- require 'test_markup_plugin' unless defined?(TestMarkupPlugin)
1
+ require 'helper'
2
+ require 'fixtures/markup_app/app'
3
+
4
+ class TestTagHelpers < Test::Unit::TestCase
5
+ def app
6
+ MarkupDemo.tap { |app| app.set :environment, :test }
7
+ end
2
8
 
3
- class TestTagHelpers < TestMarkupPlugin
4
9
  context 'for #tag method' do
5
10
  should("support tags with no content no attributes") do
6
- assert_equal '<br />', tag(:br)
11
+ assert_equal '<br />', tag(:br)
7
12
  end
8
13
  should("support tags with no content with attributes") do
9
14
  assert_equal '<br class="yellow" style="clear:both" />', tag(:br, :style => 'clear:both', :class => 'yellow')
@@ -15,7 +20,7 @@ class TestTagHelpers < TestMarkupPlugin
15
20
  assert_equal '<p class="large" id="intro">Demo</p>', tag(:p, :content => "Demo", :class => 'large', :id => 'intro')
16
21
  end
17
22
  end
18
-
23
+
19
24
  context 'for #content_tag method' do
20
25
  should "support tags with content as parameter" do
21
26
  assert_equal '<p class="large" id="intro">Demo</p>', content_tag(:p, "Demo", :class => 'large', :id => 'intro')
@@ -28,7 +33,7 @@ class TestTagHelpers < TestMarkupPlugin
28
33
  assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1'
29
34
  assert_have_selector :p, :content => "Test 2"
30
35
  # TODO get these to work in erb
31
- # assert_have_selector :p, :content => "Test 3"
36
+ # assert_have_selector :p, :content => "Test 3"
32
37
  # assert_have_selector :p, :content => "Test 4"
33
38
  end
34
39
  should "support tags with haml" do
@@ -39,7 +44,7 @@ class TestTagHelpers < TestMarkupPlugin
39
44
  assert_have_selector :p, :content => "Test 4"
40
45
  end
41
46
  end
42
-
47
+
43
48
  context 'for #input_tag method' do
44
49
  should "support field with type" do
45
50
  assert_equal '<input type="text" />', input_tag(:text)
@@ -48,5 +53,5 @@ class TestTagHelpers < TestMarkupPlugin
48
53
  assert_equal '<input class="first" id="texter" type="text" />', input_tag(:text, :class => "first", :id => 'texter')
49
54
  end
50
55
  end
51
-
52
- end
56
+
57
+ end
@@ -39,6 +39,9 @@ class TestRenderPlugin < Test::Unit::TestCase
39
39
  should "render partial html with object" do
40
40
  assert_have_selector "h1", :content => "User name is John"
41
41
  end
42
+ should "have no counter index for single item" do
43
+ assert_have_no_selector "p", :content => "My counter is 1", :count => 1
44
+ end
42
45
  end
43
46
 
44
47
  context 'for #partial method and collection' do
@@ -47,6 +50,10 @@ class TestRenderPlugin < Test::Unit::TestCase
47
50
  assert_have_selector "h1", :content => "User name is John"
48
51
  assert_have_selector "h1", :content => "User name is Billy"
49
52
  end
53
+ should "include counter which contains item index" do
54
+ assert_have_selector "p", :content => "My counter is 1"
55
+ assert_have_selector "p", :content => "My counter is 2"
56
+ end
50
57
  end
51
58
 
52
59
  context 'for #partial method and locals' do
@@ -54,6 +61,9 @@ class TestRenderPlugin < Test::Unit::TestCase
54
61
  should "render partial html with locals" do
55
62
  assert_have_selector "h1", :content => "User name is John"
56
63
  end
64
+ should "have no counter index for single item" do
65
+ assert_have_no_selector "p", :content => "My counter is 1", :count => 1
66
+ end
57
67
  end
58
68
 
59
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
@@ -75,7 +75,6 @@ files:
75
75
  - test/markup_plugin/test_format_helpers.rb
76
76
  - test/markup_plugin/test_output_helpers.rb
77
77
  - test/markup_plugin/test_tag_helpers.rb
78
- - test/test_markup_plugin.rb
79
78
  - test/test_render_plugin.rb
80
79
  - test/test_warden_plugin.rb
81
80
  has_rdoc: true
@@ -117,6 +116,5 @@ test_files:
117
116
  - test/markup_plugin/test_format_helpers.rb
118
117
  - test/markup_plugin/test_output_helpers.rb
119
118
  - test/markup_plugin/test_tag_helpers.rb
120
- - test/test_markup_plugin.rb
121
119
  - test/test_render_plugin.rb
122
120
  - test/test_warden_plugin.rb
@@ -1,15 +0,0 @@
1
- require 'helper'
2
- require 'fixtures/markup_app/app'
3
-
4
- class TestMarkupPlugin < Test::Unit::TestCase
5
- include SinatraMore::OutputHelpers
6
- include SinatraMore::TagHelpers
7
-
8
- def app
9
- MarkupDemo.tap { |app| app.set :environment, :test }
10
- end
11
-
12
- should "work properly by adding tag methods" do
13
- assert self.respond_to?(:tag)
14
- end
15
- end