sinatra-partial 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +8 -0
  4. data/CHANGES.markdown +38 -0
  5. data/Gemfile +20 -0
  6. data/README.markdown +40 -1
  7. data/Rakefile +35 -0
  8. data/examples/app_no_underscores/app.rb +13 -6
  9. data/examples/app_no_underscores/views/layout.haml +1 -1
  10. data/examples/app_no_underscores/views/meta.haml +2 -1
  11. data/examples/app_no_underscores/views/news.haml +1 -1
  12. data/examples/app_with_underscores/app.rb +16 -9
  13. data/examples/app_with_underscores/views/_meta.haml +2 -1
  14. data/examples/app_with_underscores/views/_news.haml +1 -1
  15. data/examples/app_with_underscores/views/layout.haml +1 -1
  16. data/examples/app_with_underscores_and_erb/app.rb +16 -11
  17. data/examples/app_with_underscores_and_erb/views/_meta.erb +3 -1
  18. data/examples/app_with_underscores_and_erb/views/_news.erb +1 -1
  19. data/examples/app_with_underscores_and_erb/views/layout.erb +1 -1
  20. data/examples/app_with_underscores_and_erb_and_subdirs/app.rb +17 -10
  21. data/examples/app_with_underscores_and_erb_and_subdirs/views/layout.erb +1 -1
  22. data/examples/app_with_underscores_and_erb_and_subdirs/views/partials/_meta.erb +3 -1
  23. data/examples/app_with_underscores_and_erb_and_subdirs/views/partials/_news.erb +1 -1
  24. data/examples/ext/kernel.rb +7 -0
  25. data/examples/whitespace_remove.rb +19 -0
  26. data/lib/sinatra/partial/version.rb +1 -1
  27. data/lib/sinatra/partial.rb +35 -19
  28. data/spec/examples_spec.rb +31 -0
  29. data/spec/sinatra_partial_helpers_spec.rb +19 -0
  30. data/spec/sinatra_partial_private_spec.rb +37 -0
  31. data/spec/spec_helper.rb +43 -0
  32. metadata +26 -8
  33. data/CHANGES +0 -5
data/.gitignore CHANGED
@@ -9,3 +9,10 @@ thin/
9
9
  run/
10
10
  app/.sass-cache/
11
11
  *.gem
12
+ .bundle/
13
+ Gemfile.lock
14
+ vendor/
15
+ .yardoc/
16
+ bin/
17
+ docs/
18
+ coverage/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ruby-head
7
+ bundler_args: --binstubs --path vendor
8
+ script: bundle exec rspec spec
data/CHANGES.markdown ADDED
@@ -0,0 +1,38 @@
1
+ ## v0.3.0 ##
2
+
3
+ 23rd of April 2012
4
+
5
+ * Improved specs.
6
+ * Examples are slightly more complex, since the specs required it, which also helps to clarify use.
7
+ * Tested and passing for Ruby 1.8.7, 1.9.2 and 1.9.3.
8
+ * Project added to Travis CI.
9
+ * More documentation.
10
+ * Better organised development (at last!)
11
+ * A Rake file has arrived!
12
+
13
+
14
+ ## v0.2.1 ##
15
+
16
+ 10th of April 2012
17
+
18
+ Sam Elliott provided a lot of helpful code to add in features that were lost from his gist, so many thanks to him.
19
+
20
+ * Different template engines other than Haml may be specified
21
+ * Leading underscores (a la Rails) can be specified for partials too.
22
+ * The lib is now a Sinatra Extension so the template engine and leading underscores can be configured for the application as a whole (and still overriden at call time).
23
+ * Examples have been added to the examples directory
24
+ * The code docs are much more extensive.
25
+
26
+
27
+ ## v0.1.1 ##
28
+
29
+ 9th of December 2011
30
+
31
+ * Improved the examples in the Readme file. A lot.
32
+
33
+
34
+ ## v0.1.0 ##
35
+
36
+ 4th of July 2011
37
+
38
+ * The locals hash doesn't get clobbered if passing a collection now, but you do get the chance to clobber the default of passing the collection local if you so wish. With great power comes great responsibility!
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source :rubygems
2
+
3
+ group :development do
4
+ gem "rake"
5
+ gem "wirble"
6
+ gem "reek"
7
+ gem "maruku"
8
+ gem "yard"
9
+ gem "travis-lint"
10
+ end
11
+
12
+ group :test do
13
+ gem "rake"
14
+ gem "rack-test"
15
+ gem "rspec"
16
+ gem "simplecov"
17
+ gem "sinatra"
18
+ gem "haml"
19
+ gem 'timecop'
20
+ end
data/README.markdown CHANGED
@@ -1,10 +1,12 @@
1
+ [![Build Status for development branch](https://secure.travis-ci.org/yb66/Sinatra-Partial.png?branch=develop)](http://travis-ci.org/yb66/Sinatra-Partial)
2
+
1
3
  ## Sinatra Partial ##
2
4
 
3
5
  Partials for Sinatra!
4
6
 
5
7
  ### Quick note ###
6
8
 
7
- If you do decide to use this gem, please let me know if it isn't working for you - make a contribution! Github makes it so simple..!
9
+ If you do decide to use this gem, please let me know if it isn't working for you - make a contribution! Github makes it so simple..! See the Contribution section for more.
8
10
 
9
11
  Back to our previously scheduled programming...
10
12
 
@@ -182,6 +184,43 @@ Look in the examples directory for some very simple examples.
182
184
 
183
185
  Thanks to Chris Schneider and Sam Elliott for sharing their code, and for sharing further updates.
184
186
 
187
+ ### Contributing ###
188
+
189
+ Most of all, remember that **any** contribution you can make will be valuable, whether that is putting in a ticket for a feature request (or a bug, but they don't happen here;), cleaning up some grammar, writing some documentation (or even a blog post, let me know!) or a full blooded piece of code - it's **all** welcome and encouraged.
190
+
191
+ To contribute some code:
192
+
193
+ 1. Fork this.
194
+ * `git clone git@github.com:YOUR_USERNAME/Sinatra-Partial.git`
195
+ * `git remote add upstream git://github.com/yb66/Sinatra-Partial.git`
196
+ * `git fetch upstream`
197
+ * `git checkout develop`
198
+ * Decide on the feature you wish to add.
199
+ - Give it a snazzy name, such as kitchen_sink.
200
+ - `git checkout -b kitchen_sink`
201
+ * Install Bundler.
202
+ - `gem install bundler -r --no-ri --no-rdoc`
203
+ - Any further updates needed, just run `bundle install`, it'll remember the rest.
204
+ * Install gems from Gemfile.
205
+ - `bundle install --binstubs --path vendor`
206
+ * Write some specs.
207
+ * Write some code. (Yes, I believe that is the correct order, and you'll never find me doing any different;)
208
+ * Write some documentation using Yard comments - see http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
209
+ - Use real English (i.e. full stops and commas, no l33t or LOLZ). I'll accept American English even though it's ugly. Don't be surprised if I 'correct' it.
210
+ - Code without comments won't get in, I don't have the time to work out what you've done if you're not prepared to spend some time telling me (and everyone else).
211
+ * Run `reek PATH_TO_FILE_WITH_YOUR_CHANGES` and see if it gives you any good advice. You don't have to do what it says, just consider it.
212
+ * Run specs to make sure you've not broken anything. If it doesn't pass all the specs it doesn't get in.
213
+ - Have a look at coverage/index.htm and see if all your code was checked. We're trying for 100% code coverage.
214
+ * Run `bin/rake docs` to generate documentation.
215
+ - Open up docs/index.html and check your documentation has been added and is clear.
216
+ * Add a short summary of your changes to the CHANGES file. Add your name and a link to your bio/website if you like too.
217
+ * Send me a pull request.
218
+ - Don't merge into the develop branch!
219
+ - Don't merge into the master branch!
220
+ - see http://nvie.com/posts/a-successful-git-branching-model/ for more on how this is supposed to work.
221
+ * Wait for worldwide fame.
222
+ * Shrug and get on with you life when it doesn't arrive, but know you helped quite a few people in their life, even in a small way - 1000 raindrops will fill a bucket!
223
+
185
224
 
186
225
  ### Licence ###
187
226
 
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rake'
4
+
5
+ task :default => "spec"
6
+
7
+
8
+ desc "(Re-) generate documentation and place it in the docs/ dir."
9
+ task :docs => :"docs:yard"
10
+ namespace :docs do
11
+ require 'yard'
12
+ YARD::Rake::YardocTask.new do |t|
13
+ t.files = ['lib/**/*.rb']
14
+ t.options = ['-odocs/', '--no-private']
15
+ end
16
+
17
+ desc "Docs including private methods."
18
+ YARD::Rake::YardocTask.new(:all) do |t|
19
+ t.files = ['lib/**/*.rb']
20
+ t.options = ['-odocs/']
21
+ end
22
+
23
+ desc "How to use the docs."
24
+ task :usage do
25
+ puts "Open the index.html file in the docs directory to read them. Does not include methods marked private unless you ran the 'all' version (you'll only need these if you plan to hack on the library itself)."
26
+ end
27
+ end
28
+
29
+
30
+ require 'rspec/core/rake_task'
31
+
32
+ desc "Run specs"
33
+ RSpec::Core::RakeTask.new do |t|
34
+ t.pattern = "./spec/**/*_spec.rb"
35
+ end
@@ -1,10 +1,17 @@
1
- require 'sinatra'
2
- require_relative "../../lib/sinatra/partial.rb"
1
+ require 'sinatra/base'
3
2
  require 'haml'
3
+ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
4
+ require_relative "../../lib/sinatra/partial.rb"
5
+ require_relative "../whitespace_remove.rb"
4
6
 
5
- News = ["This", "is", "all", "new"]
6
7
 
7
- get "/" do
8
- haml :home
8
+ class AppNoUnderscores < Sinatra::Base
9
+ register Sinatra::Partial
10
+ use WhiteSpaceRemove
11
+
12
+ News = ["This", "is", "all", "new"]
13
+
14
+ get "/" do
15
+ haml :home
16
+ end
9
17
  end
10
-
@@ -4,7 +4,7 @@
4
4
  = partial :meta
5
5
 
6
6
  %ul
7
- = partial :news, :collection => News
7
+ = partial :news, :collection => News, :locals => {:klass => {:class => "klassic"}}
8
8
 
9
9
  = partial :locality, :locals => Hash[%w{a b c d}.zip(%w{A B C D})]
10
10
 
@@ -1 +1,2 @@
1
- Time is #{Time.now.localtime}
1
+ %p
2
+ Time is #{Time.now.localtime}
@@ -1,2 +1,2 @@
1
- %li
1
+ %li{ klass }
2
2
  = news
@@ -1,12 +1,19 @@
1
- require 'sinatra'
2
- require_relative "../../lib/sinatra/partial.rb"
1
+ require 'sinatra/base'
3
2
  require 'haml'
3
+ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
4
+ require_relative "../../lib/sinatra/partial.rb"
5
+ require_relative "../whitespace_remove.rb"
4
6
 
5
- News = ["This", "is", "all", "new"]
6
-
7
- set :partial_underscores, true
8
-
9
- get "/" do
10
- haml :home
7
+ class AppWithUnderscores < Sinatra::Base
8
+ register Sinatra::Partial
9
+ use WhiteSpaceRemove
10
+
11
+ News = ["This", "is", "all", "new"]
12
+
13
+ set :partial_underscores, true
14
+
15
+
16
+ get "/" do
17
+ haml :home
18
+ end
11
19
  end
12
-
@@ -1 +1,2 @@
1
- Time is #{Time.now.localtime}
1
+ %p
2
+ Time is #{Time.now.localtime}
@@ -1,2 +1,2 @@
1
- %li
1
+ %li{ klass }
2
2
  = news
@@ -4,7 +4,7 @@
4
4
  = partial :meta
5
5
 
6
6
  %ul
7
- = partial :news, :collection => News
7
+ = partial :news, :collection => News, :locals => {:klass => {:class => "klassic"}}
8
8
 
9
9
  = partial :locality, :locals => Hash[%w{a b c d}.zip(%w{A B C D})]
10
10
 
@@ -1,14 +1,19 @@
1
- require 'sinatra'
1
+ require 'sinatra/base'
2
+ require 'erb'
3
+ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
2
4
  require_relative "../../lib/sinatra/partial.rb"
3
- require 'haml'
5
+ require_relative "../whitespace_remove.rb"
4
6
 
5
- News = ["This", "is", "all", "new"]
6
-
7
- set :partial_underscores, true
8
- set :partial_template_engine, :erb
9
-
10
-
11
- get "/" do
12
- erb :home
13
- end
7
+ class AppWithUnderscoresAndErb < Sinatra::Base
8
+ register Sinatra::Partial
9
+ use WhiteSpaceRemove
14
10
 
11
+ News = ["This", "is", "all", "new"]
12
+
13
+ set :partial_underscores, true
14
+ set :partial_template_engine, :erb
15
+
16
+ get "/" do
17
+ erb :home
18
+ end
19
+ end
@@ -1 +1,3 @@
1
- Time is <%= Time.now.localtime %>
1
+ <p>
2
+ Time is <%= Time.now.localtime %>
3
+ </p>
@@ -1,3 +1,3 @@
1
- <li>
1
+ <li <%= klass.map{|k,v| "#{k}='#{v}'" }.join(" ") %>>
2
2
  <%= news %>
3
3
  </li>
@@ -4,7 +4,7 @@
4
4
  <%= partial :meta %>
5
5
 
6
6
  <ul>
7
- <%= partial :news, :collection => News %>
7
+ <%= partial :news, :collection => News, :locals => {:klass => {:class => "klassic"}} %>
8
8
  </ul>
9
9
 
10
10
  <%= partial( :locality, :locals => Hash[%w{a b c d}.zip(%w{A B C D})]) %>
@@ -1,14 +1,21 @@
1
- require 'sinatra'
1
+ require 'sinatra/base'
2
+ require 'erb'
3
+ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
2
4
  require_relative "../../lib/sinatra/partial.rb"
3
- require 'haml'
5
+ require_relative "../whitespace_remove.rb"
4
6
 
5
- News = ["This", "is", "all", "new"]
6
-
7
- set :partial_underscores, true
8
- set :partial_template_engine, :erb
9
-
10
-
11
- get "/" do
12
- erb :home
7
+ class AppWithUnderscoresAndErbAndSubdirs < Sinatra::Base
8
+ register Sinatra::Partial
9
+ use WhiteSpaceRemove
10
+
11
+ News = ["This", "is", "all", "new"]
12
+
13
+ set :partial_underscores, true
14
+ set :partial_template_engine, :erb
15
+
16
+
17
+ get "/" do
18
+ erb :home
19
+ end
13
20
  end
14
21
 
@@ -4,7 +4,7 @@
4
4
  <%= partial :"partials/meta" %>
5
5
 
6
6
  <ul>
7
- <%= partial :"partials/news", :collection => News %>
7
+ <%= partial :"partials/news", :collection => News, :locals => {:klass => {:class => "klassic"}} %>
8
8
  </ul>
9
9
 
10
10
  <%= partial( :"partials/locality", :locals => Hash[%w{a b c d}.zip(%w{A B C D})]) %>
@@ -1 +1,3 @@
1
- Time is <%= Time.now.localtime %>
1
+ <p>
2
+ Time is <%= Time.now.localtime %>
3
+ </p>
@@ -1,3 +1,3 @@
1
- <li>
1
+ <li <%= klass.map{|k,v| "#{k}='#{v}'" }.join(" ") %>>
2
2
  <%= news %>
3
3
  </li>
@@ -0,0 +1,7 @@
1
+ unless Kernel.respond_to?(:require_relative)
2
+ module Kernel
3
+ def require_relative(path)
4
+ require File.join(File.dirname(caller[0]), path.to_str)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ ## Here to strip out whitespace, because ERB (can you believe it?) doesn't use whitespace well. Many thanks to http://stackoverflow.com/questions/8827845/how-do-i-strip-html-whitespace-in-erb-templates#answer-8828830
4
+ class WhiteSpaceRemove
5
+ def initialize(app, options = {})
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ status, headers, response = @app.call(env)
11
+
12
+ if headers["Content-Type"] =~ /\bhtml\b/
13
+ response[0] = response[0].gsub(/\s*(<[^>]+>)\s*/, '\1')
14
+ headers["Content-Length"] = response[0].size.to_s
15
+ end
16
+
17
+ [status, headers, response]
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Partial
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -4,10 +4,35 @@ require 'sinatra/base'
4
4
 
5
5
  module Sinatra
6
6
  module Partial
7
+
8
+ # This is here to make testing the private code easier while not including it in the helpers.
9
+ module Private
10
+
11
+ # This gets the path to the template, taking into account whether leading underscores are needed.
12
+ # @private
13
+ # param [String] partial_path
14
+ # param [true,false,nil] underscores Defaults to false
15
+ def self.partial_expand_path(partial_path, underscores=false)
16
+ underscores ||= false
17
+ dirs, base = [File.dirname(partial_path),File.basename(partial_path)]
18
+ base.insert(0, "_") if underscores
19
+ File.join(dirs, base).to_sym
20
+ end
21
+
22
+ # This takes the name of the local from the template's name, and corrects local by removing leading underscore if it's there.
23
+ # @private
24
+ # param [String] partial_path
25
+ def self.partial_local(partial_path)
26
+ partial_path = partial_path[1..-1] if partial_path.start_with? "_"
27
+ File.basename(partial_path).to_sym
28
+ end
29
+ end
30
+
31
+
7
32
  module Helpers
8
33
  # Renders a partial to a string.
9
34
  #
10
- # @param [#to_s] partial The partial to render.
35
+ # @param [#to_s] partial_name The partial to render.
11
36
  # @param [Hash] options The options to render the partial with.
12
37
  # @option options [Hash] :locals Local variables to render with
13
38
  # @option options [Array] :collection Renders the template once per object in this array.
@@ -28,17 +53,17 @@ module Sinatra
28
53
  # partial(:"meta/news", :collection => [<News>])
29
54
  # # => renders views/meta/_news.haml once per item in :collection,
30
55
  # with the local variable `news` being the current item in the iteration
31
- def partial(partial, options={})
32
- partial_location = partial.to_s
33
-
34
- locals = options.fetch(:locals, {})
56
+ def partial(partial_name, options={})
57
+ partial_location = partial_name.to_s
35
58
  engine = options.fetch(:template_engine, settings.partial_template_engine)
36
59
  underscores = options.fetch(:underscores, settings.partial_underscores)
37
60
 
38
- template = partial_expand_path(partial_location, underscores)
61
+ template = Private.partial_expand_path(partial_location, underscores)
39
62
 
40
63
  if collection = options.delete(:collection)
41
- member_local = partial_local(partial_location)
64
+ member_local = Private.partial_local(partial_location)
65
+
66
+ locals = options.fetch(:locals, {})
42
67
 
43
68
  collection.inject([]) do |buffer, member|
44
69
  new_locals = {member_local => member}.merge(locals)
@@ -49,19 +74,10 @@ module Sinatra
49
74
  end
50
75
  end
51
76
 
52
- private
53
-
54
- def partial_expand_path(partial_path, underscores=false)
55
- dirs, base = [File.dirname(partial_path),File.basename(partial_path)]
56
- base.insert(0, "_") if underscores
57
- File.join(dirs, base).to_sym
58
- end
59
-
60
- def partial_local(partial_path)
61
- File.basename(partial_path).to_sym
62
- end
63
- end
77
+ end # of Helpers
64
78
 
79
+ # This is here to allow configuration options to be set.
80
+ # @private
65
81
  def self.registered(app)
66
82
  app.helpers(Partial::Helpers)
67
83
 
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+
5
+ require_relative "../lib/sinatra/partial.rb"
6
+
7
+ require_relative "../examples/app_no_underscores/app.rb"
8
+ require_relative "../examples/app_with_underscores/app.rb"
9
+ require_relative "../examples/app_with_underscores_and_erb/app.rb"
10
+ require_relative "../examples/app_with_underscores_and_erb_and_subdirs/app.rb"
11
+
12
+ shared_examples_for "all in examples dir" do
13
+ let(:expected) { "<html><head></head><body><p>Time is #{Time.now}</p><ul><li class='klassic'>This</li><li class='klassic'>is</li><li class='klassic'>all</li><li class='klassic'>new</li></ul><p>A is A</p><p>B is B</p><p>C is C</p><p>D is D</p><p>Hello, World</p></body></html>" }
14
+ subject { browser.last_response }
15
+ it { should be_ok }
16
+ it { subject.body.should == expected }
17
+ end
18
+
19
+ def new_session( app )
20
+ Rack::Test::Session.new(Rack::MockSession.new( app ) )
21
+ end
22
+
23
+ Apps = [AppNoUnderscores, AppWithUnderscores, AppWithUnderscoresAndErb, AppWithUnderscoresAndErbAndSubdirs]
24
+
25
+ Apps.each do |app|
26
+ describe app.to_s do
27
+ let(:browser){ new_session( app ) }
28
+ before{ browser.get '/' }
29
+ it_should_behave_like "all in examples dir"
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+ require_relative "../lib/sinatra/partial.rb"
5
+
6
+
7
+ describe "Helpers::partial" do
8
+
9
+ engines = [:haml, :erb]
10
+ underscores = [true, false]
11
+ partials = ["news", "meta/news"]
12
+ engines.product(underscores).product(partials).map{|x| x.flatten}.each do |(engine, underscore, partial)|
13
+ context "Engine: #{engine} Underscores: #{underscore}, Partial: #{partial}" do
14
+ let(:settings) { OpenStruct.new({:partial_template_engine => engine, :underscores => underscore}) }
15
+
16
+ pending "Need to find a way to run spec without Sinatra, which so far is proving tricky, as that's kind of the point."
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+
3
+ require "spec_helper"
4
+ require_relative "../lib/sinatra/partial.rb"
5
+
6
+
7
+ describe "partial_expand_path" do
8
+
9
+ subject{ Sinatra::Partial::Private.partial_expand_path( partial_path, underscores ) }
10
+
11
+ context "Given a single word" do
12
+ let(:partial_path) { "news" }
13
+ context "and underscores is set to false." do
14
+ let(:expected) { :"./news" }
15
+ let(:underscores) { false }
16
+ it { should == expected }
17
+ end
18
+ context "and underscores is set to true." do
19
+ let(:expected) { :"./_news" }
20
+ let(:underscores) { true }
21
+ it { should == expected }
22
+ end
23
+ end
24
+ context "Given a path" do
25
+ let(:partial_path) { "meta/news" }
26
+ context "and underscores is set to false." do
27
+ let(:expected) { :"meta/news" }
28
+ let(:underscores) { false }
29
+ it { should == expected }
30
+ end
31
+ context "and underscores is set to true." do
32
+ let(:expected) { :"meta/_news" }
33
+ let(:underscores) { true }
34
+ it { should == expected }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rspec'
4
+ Spec_dir = File.expand_path( File.dirname __FILE__ )
5
+ unless Kernel.respond_to?(:require_relative)
6
+ module Kernel
7
+ def require_relative(path)
8
+ require File.join(File.dirname(caller[0]), path.to_str)
9
+ end
10
+ end
11
+ end
12
+
13
+ # code coverage
14
+ require 'simplecov'
15
+ SimpleCov.start do
16
+ add_filter "/vendor/"
17
+ end
18
+
19
+ require "rack/test"
20
+ ENV['RACK_ENV'] ||= 'test'
21
+ ENV["EXPECT_WITH"] ||= "racktest"
22
+
23
+ require "logger"
24
+ logger = Logger.new STDOUT
25
+ logger.level = Logger::DEBUG
26
+ logger.datetime_format = '%a %d-%m-%Y %H%M '
27
+ LOgger = logger
28
+
29
+
30
+ Dir[ File.join( Spec_dir, "/support/**/*.rb")].each do |f|
31
+ puts "requiring #{f}"
32
+ require f
33
+ end
34
+
35
+
36
+ RSpec.configure do |config|
37
+ config.treat_symbols_as_metadata_keys_with_true_values = true
38
+ config.include Rack::Test::Methods
39
+ end
40
+
41
+ # freeze time!
42
+ require 'timecop'
43
+ Timecop.freeze( Date.today )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-partial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-10 00:00:00.000000000 Z
14
+ date: 2012-04-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: sinatra
18
- requirement: &2156135160 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,7 +23,12 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2156135160
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
27
32
  description: Just the partials helper in a gem. That is all.
28
33
  email:
29
34
  - iainspeed@gmail.com
@@ -32,8 +37,12 @@ extensions: []
32
37
  extra_rdoc_files: []
33
38
  files:
34
39
  - .gitignore
35
- - CHANGES
40
+ - .rspec
41
+ - .travis.yml
42
+ - CHANGES.markdown
43
+ - Gemfile
36
44
  - README.markdown
45
+ - Rakefile
37
46
  - examples/app_no_underscores/app.rb
38
47
  - examples/app_no_underscores/views/home.haml
39
48
  - examples/app_no_underscores/views/layout.haml
@@ -58,9 +67,15 @@ files:
58
67
  - examples/app_with_underscores_and_erb_and_subdirs/views/partials/_locality.erb
59
68
  - examples/app_with_underscores_and_erb_and_subdirs/views/partials/_meta.erb
60
69
  - examples/app_with_underscores_and_erb_and_subdirs/views/partials/_news.erb
70
+ - examples/ext/kernel.rb
71
+ - examples/whitespace_remove.rb
61
72
  - lib/sinatra/partial.rb
62
73
  - lib/sinatra/partial/version.rb
63
74
  - sinatra-partial.gemspec
75
+ - spec/examples_spec.rb
76
+ - spec/sinatra_partial_helpers_spec.rb
77
+ - spec/sinatra_partial_private_spec.rb
78
+ - spec/spec_helper.rb
64
79
  homepage: https://github.com/yb66/Sinatra-Partial
65
80
  licenses:
66
81
  - MIT
@@ -82,9 +97,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
97
  version: '0'
83
98
  requirements: []
84
99
  rubyforge_project:
85
- rubygems_version: 1.8.10
100
+ rubygems_version: 1.8.22
86
101
  signing_key:
87
102
  specification_version: 3
88
103
  summary: A sinatra extension for render partials.
89
- test_files: []
90
- has_rdoc:
104
+ test_files:
105
+ - spec/examples_spec.rb
106
+ - spec/sinatra_partial_helpers_spec.rb
107
+ - spec/sinatra_partial_private_spec.rb
108
+ - spec/spec_helper.rb
data/CHANGES DELETED
@@ -1,5 +0,0 @@
1
- v0.2.1 Sam Elliott provided a lot of helpful code to add in features that were lost from his gist. Further to these, the lib is now a Sinatra Extension so it can add in some useful defaults. Different template engines other than Haml may be specified, and leading underscores (a la Rails) can be specified for partials too. Examples have been added to the examples directory, and the code docs are much more extensive.
2
-
3
- v0.1.1 Improved the examples in the Readme file. A lot.
4
-
5
- v0.1.0 The locals hash doesn't get clobbered if passing a collection now, but you do get the chance to clobber the default of passing the collection local if you so wish. With great power comes great responsibility!