hobbit-contrib 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55fab9ef331ed253a8f11ec44ae25fc53da572dd
4
- data.tar.gz: 089a7b5a8fbbbb5454d48980c982cc89b6a7db82
3
+ metadata.gz: b7605fffd9d4c2602f35c6556529d11bafb64883
4
+ data.tar.gz: 58af370162d53892f0f966e18b0fd8daaf49c1e7
5
5
  SHA512:
6
- metadata.gz: 72e7ecc6ea472c0003dc5b0ccd7f11c9e7b414d73e914cc283b5aeef0692c4da20b97b887375052142e0c751a813b04ff2f263b52383160d41087632a8d23ea5
7
- data.tar.gz: 852457cfe4f155c9c81d8750d9d7b7f3a3aa6577b28aece8dd1369cf0243055cd854d28b627ca2575fdb21eb088d735a81d4edc327ddd29dfcbff292cc854b8f
6
+ metadata.gz: 9ccf2711a81fd56a5405cf9989843263261a8436d40e984b23e5b9500a3591f9a73dc25d597cb91507e847bfaeecb3f47b2903181b975a663cb17755f624d684
7
+ data.tar.gz: 239c9527fbdd4485e311414b319f75d7ba8764e64368dd28f72daafeb8c6449b5348ba0079f3335393cb1cb62aae3820bfb3e271bbe5876a07aacd374874b1ed
data/.travis.yml CHANGED
@@ -3,3 +3,7 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1.0
5
5
  - ruby-head
6
+ addons:
7
+ code_climate:
8
+ repo_token:
9
+ secure: "L2qK51BSckPkJpBqSEIdiGZzd/iBebueZh3Vn5C14uBGfJasfq1cp7rwBvoaJRZ4kYPl6ZvyD9KGIbfzzhYFgC0cMwNaMsk2koV37IB+kKCek7JTOqEmvdHW8mfWAtaVL4HMm+MhXJq6JhxUvSmFLDMLtmtlwm77gTWKvT2afyE="
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.5.2
2
+
3
+ * Add `Hobbit::Mote`
4
+
1
5
  # 0.5.1
2
6
 
3
7
  * Fix broken tests.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Hobbit::Contrib [![Build Status](https://travis-ci.org/patriciomacadden/hobbit-contrib.png?branch=master)](https://travis-ci.org/patriciomacadden/hobbit-contrib) [![Code Climate](https://codeclimate.com/github/patriciomacadden/hobbit-contrib.png)](https://codeclimate.com/github/patriciomacadden/hobbit-contrib) [![Coverage Status](https://coveralls.io/repos/patriciomacadden/hobbit-contrib/badge.png?branch=master)](https://coveralls.io/r/patriciomacadden/hobbit-contrib) [![Dependency Status](https://gemnasium.com/patriciomacadden/hobbit-contrib.png)](https://gemnasium.com/patriciomacadden/hobbit-contrib) [![Gem Version](https://badge.fury.io/rb/hobbit-contrib.png)](http://badge.fury.io/rb/hobbit-contrib)
1
+ # Hobbit::Contrib [![Build Status](http://img.shields.io/travis/patriciomacadden/hobbit-contrib.svg)](https://travis-ci.org/patriciomacadden/hobbit-contrib) [![Code Climate](http://img.shields.io/codeclimate/github/patriciomacadden/hobbit-contrib.svg)](https://codeclimate.com/github/patriciomacadden/hobbit-contrib) [![Code Climate Coverage](http://img.shields.io/codeclimate/coverage/github/patriciomacadden/hobbit-contrib.svg)](https://codeclimate.com/github/patriciomacadden/hobbit-contrib) [![Dependency Status](http://img.shields.io/gemnasium/patriciomacadden/hobbit-contrib.svg)](https://gemnasium.com/patriciomacadden/hobbit-contrib) [![Gem Version](http://img.shields.io/gem/v/hobbit-contrib.svg)](http://badge.fury.io/rb/hobbit-contrib)
2
2
 
3
3
  Contributed Hobbit extensions.
4
4
 
@@ -144,6 +144,39 @@ run App.new
144
144
  **Note**: It is recommended to include `Hobbit::Filter` before
145
145
  `Hobbit::ErrorHandling` if you want to use both extensions.
146
146
 
147
+ ### Hobbit::Mote
148
+
149
+ This module provides rendering to your hobbit application using [mote](https://github.com/soveran/mote).
150
+ To use this extension just include the module:
151
+
152
+ ```ruby
153
+ require 'hobbit'
154
+ require 'hobbit/contrib'
155
+
156
+ class App < Hobbit::Base
157
+ include Hobbit::Mote
158
+
159
+ get '/' do
160
+ # will render views/index.mote using views/layouts/application.mote as layout
161
+ render 'index'
162
+ end
163
+ end
164
+ ```
165
+
166
+ #### Available methods
167
+
168
+ * `default_layout`: Returns the name of the default layout (Override to use
169
+ another layout).
170
+ * `find_template`: Returns the path to a template (Override for multiple views
171
+ paths lookup).
172
+ * `layouts_path`: Returns the layouts path (Override to change the layouts
173
+ directory).
174
+ * `partial`: Renders the given template using tilt (without a layout).
175
+ * `render`: Renders the given template using tilt. You can pass a `layout`
176
+ option to change the layout (or set to `false` to not use one).
177
+ * `views_path`: Returns the views path (Override to change the views
178
+ directory).
179
+
147
180
  ### Hobbit::Render
148
181
 
149
182
  This module provides rendering to your hobbit application. To use this
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['patriciomacadden@gmail.com']
11
11
  spec.description = %q{Contributed Hobbit extensions}
12
12
  spec.summary = %q{Contributed Hobbit extensions}
13
- spec.homepage = ''
13
+ spec.homepage = 'https://github.com/patriciomacadden/hobbit-contrib'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -19,12 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
- spec.add_development_dependency 'coveralls'
22
+ spec.add_development_dependency 'codeclimate-test-reporter'
23
23
  spec.add_development_dependency 'minitest'
24
24
  spec.add_development_dependency 'rack-test'
25
25
  spec.add_development_dependency 'rake'
26
26
 
27
+ spec.add_runtime_dependency 'erubis'
27
28
  spec.add_runtime_dependency 'hobbit'
29
+ spec.add_runtime_dependency 'mote'
28
30
  spec.add_runtime_dependency 'tilt'
29
- spec.add_runtime_dependency 'erubis'
30
31
  end
@@ -2,5 +2,6 @@ require 'hobbit/contrib/version'
2
2
  require 'hobbit/environment'
3
3
  require 'hobbit/error_handling'
4
4
  require 'hobbit/filter'
5
+ require 'hobbit/mote'
5
6
  require 'hobbit/render'
6
7
  require 'hobbit/session'
@@ -1,5 +1,5 @@
1
1
  module Hobbit
2
2
  module Contrib
3
- VERSION = '0.5.1'
3
+ VERSION = '0.5.2'
4
4
  end
5
5
  end
@@ -0,0 +1,44 @@
1
+ require 'mote'
2
+
3
+ module Hobbit
4
+ module Mote
5
+ def self.included(othermod)
6
+ othermod.send :include, ::Mote::Helpers
7
+ end
8
+
9
+ def default_layout
10
+ "#{layouts_path}/application.mote"
11
+ end
12
+
13
+ def find_template(template)
14
+ "#{views_path}/#{template}.mote"
15
+ end
16
+
17
+ def layouts_path
18
+ "#{views_path}/layouts"
19
+ end
20
+
21
+ def partial(template, params = {}, context = self)
22
+ template = find_template "_#{template}"
23
+ mote template, params, context
24
+ end
25
+
26
+ def render(template, params = {}, context = self)
27
+ template = find_template template
28
+ layout = default_layout
29
+ if params.include? :layout
30
+ layout = params.delete :layout
31
+ end
32
+ if layout
33
+ params = params.merge content: mote(template, params, context)
34
+ mote layout, params, context
35
+ else
36
+ mote template, params, context
37
+ end
38
+ end
39
+
40
+ def views_path
41
+ 'views'
42
+ end
43
+ end
44
+ end
data/lib/hobbit/render.rb CHANGED
@@ -23,8 +23,7 @@ module Hobbit
23
23
  template = find_template template
24
24
  layout = default_layout
25
25
  if options.include? :layout
26
- layout = options[:layout]
27
- options.delete :layout
26
+ layout = options.delete :layout
28
27
  end
29
28
  if layout
30
29
  _render(layout) { _render(template) }
@@ -3,7 +3,7 @@ require 'minitest_helper'
3
3
  describe Hobbit::Environment do
4
4
  include Hobbit::Contrib::Mock
5
5
 
6
- let(:app) do
6
+ let :app do
7
7
  mock_app do
8
8
  include Hobbit::Environment
9
9
  end
@@ -5,7 +5,7 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
5
5
  include Rack::Test::Methods
6
6
 
7
7
  describe 'when the exception ocurrs in a route' do
8
- let(:app) do
8
+ let :app do
9
9
  mock_app do
10
10
  include Hobbit::Filter
11
11
  include Hobbit::ErrorHandling
@@ -39,7 +39,7 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
39
39
  end
40
40
 
41
41
  describe 'when the exception ocurrs in a before filter' do
42
- let(:app) do
42
+ let :app do
43
43
  mock_app do
44
44
  include Hobbit::Filter
45
45
  include Hobbit::ErrorHandling
@@ -72,7 +72,7 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
72
72
  end
73
73
 
74
74
  describe 'when the exception ocurrs in an after filter' do
75
- let(:app) do
75
+ let :app do
76
76
  mock_app do
77
77
  include Hobbit::Filter
78
78
  include Hobbit::ErrorHandling
@@ -106,7 +106,7 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
106
106
 
107
107
  describe 'the order of the modules inclusion matters' do
108
108
  describe 'when ErrorHandling is included before Filter' do
109
- let(:app) do
109
+ let :app do
110
110
  mock_app do
111
111
  include Hobbit::ErrorHandling
112
112
  include Hobbit::Filter
@@ -9,7 +9,7 @@ describe Hobbit::ErrorHandling do
9
9
  class UnknownException < Exception ; end
10
10
  class MustUseResponseException < Exception ; end
11
11
 
12
- let(:app) do
12
+ let :app do
13
13
  mock_app do
14
14
  include Hobbit::ErrorHandling
15
15
 
data/spec/filter_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe Hobbit::Filter do
5
5
  include Rack::Test::Methods
6
6
 
7
7
  describe 'basic specs' do
8
- let(:app) do
8
+ let :app do
9
9
  mock_app do
10
10
  include Hobbit::Filter
11
11
 
@@ -110,8 +110,35 @@ EOS
110
110
  end
111
111
  end
112
112
 
113
+ describe 'filters with parameters' do
114
+ let :app do
115
+ mock_app do
116
+ include Hobbit::Filter
117
+
118
+ before '/:name' do
119
+ env['hobbit.before'] = 'this is before'
120
+ end
121
+
122
+ after '/:name' do
123
+ env['hobbit.after'] = 'this is after'
124
+ end
125
+
126
+ get('/:name') { env['hobbit.before'] }
127
+ end
128
+ end
129
+
130
+ it 'must call the before and after filters' do
131
+ get '/hobbit'
132
+ last_response.must_be :ok?
133
+ last_request.env.must_include 'hobbit.before'
134
+ last_request.env['hobbit.before'].must_equal 'this is before'
135
+ last_request.env.must_include 'hobbit.after'
136
+ last_request.env['hobbit.after'].must_equal 'this is after'
137
+ end
138
+ end
139
+
113
140
  describe 'when multiple filters are declared' do
114
- let(:app) do
141
+ let :app do
115
142
  mock_app do
116
143
  include Hobbit::Filter
117
144
 
@@ -0,0 +1,5 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head><title>Hello World!</title></head>
4
+ <body>Hello World!</body>
5
+ </html>
@@ -0,0 +1,5 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head><title>Hello {{ name }}!</title></head>
4
+ <body>Hello {{ name }}!</body>
5
+ </html>
@@ -0,0 +1 @@
1
+ <h1>Hello World!</h1>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>From application.mote</title>
5
+ </head>
6
+ <body>
7
+ {{ content }}
8
+ </body>
9
+ </html>
@@ -1,11 +1,11 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
1
4
  ENV['RACK_ENV'] ||= 'test'
2
5
 
3
6
  require 'bundler'
4
7
  Bundler.require :default, ENV['RACK_ENV'].to_sym
5
8
 
6
- require 'coveralls'
7
- Coveralls.wear!
8
-
9
9
  require 'minitest/autorun'
10
10
  require 'rack'
11
11
  require 'rack/test'
data/spec/mote_spec.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Hobbit::Mote do
4
+ include Hobbit::Contrib::Mock
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ mock_app do
9
+ include Hobbit::Mote
10
+
11
+ def views_path
12
+ File.expand_path '../fixtures/mote/views/', __FILE__
13
+ end
14
+
15
+ def name
16
+ 'Hobbit'
17
+ end
18
+
19
+ get('/') { render 'index' }
20
+ get('/partial') { partial 'partial' }
21
+ get('/using-context') { render 'hello' }
22
+ get('/without-layout') { render '_partial', layout: false }
23
+ end
24
+ end
25
+
26
+ describe '#default_layout' do
27
+ it 'defaults to application.mote' do
28
+ app.to_app.default_layout.must_equal "#{app.to_app.layouts_path}/application.mote"
29
+ end
30
+ end
31
+
32
+ describe '#find_template' do
33
+ it 'must return a template path' do
34
+ app.to_app.find_template('index').must_equal "#{app.to_app.views_path}/index.mote"
35
+ end
36
+ end
37
+
38
+ describe '#layouts_path' do
39
+ it 'must return the path to the layouts directory' do
40
+ app.to_app.layouts_path.must_equal "#{app.to_app.views_path}/layouts"
41
+ end
42
+ end
43
+
44
+ describe '#partial' do
45
+ it 'must render a template without a layout' do
46
+ get '/partial'
47
+ last_response.must_be :ok?
48
+ last_response.body.wont_match /From application.mote/
49
+ last_response.body.must_match /Hello World!/
50
+ end
51
+ end
52
+
53
+ describe '#render' do
54
+ it 'must render a template (using a layout)' do
55
+ get '/'
56
+ last_response.must_be :ok?
57
+ last_response.body.must_match /From application.mote/
58
+ last_response.body.must_match /Hello World!/
59
+ end
60
+
61
+ it 'must render a template (not using a layout)' do
62
+ get '/without-layout'
63
+ last_response.must_be :ok?
64
+ last_response.body.wont_match /From application.mote/
65
+ last_response.body.must_match /Hello World!/
66
+ end
67
+
68
+ it 'must render a template using the app as context' do
69
+ get '/using-context'
70
+ last_response.must_be :ok?
71
+ last_response.body.must_match /From application.mote/
72
+ last_response.body.must_match /Hello Hobbit!/
73
+ end
74
+ end
75
+
76
+ describe '#views_path' do
77
+ it 'must return the path to the views directory' do
78
+ app.to_app.views_path.must_equal File.expand_path('../fixtures/mote/views', __FILE__)
79
+ end
80
+
81
+ it 'defaults to "views"' do
82
+ a = mock_app do
83
+ include Hobbit::Mote
84
+ end
85
+
86
+ a.to_app.views_path.must_equal 'views'
87
+ end
88
+ end
89
+ end
data/spec/render_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'minitest_helper'
2
+ require 'tilt/erubis'
2
3
 
3
4
  describe Hobbit::Render do
4
5
  include Hobbit::Contrib::Mock
@@ -83,5 +84,13 @@ describe Hobbit::Render do
83
84
  it 'must return the path to the views directory' do
84
85
  app.to_app.views_path.must_equal File.expand_path('../fixtures/render/views', __FILE__)
85
86
  end
87
+
88
+ it 'defaults to "views"' do
89
+ a = mock_app do
90
+ include Hobbit::Render
91
+ end
92
+
93
+ a.to_app.views_path.must_equal 'views'
94
+ end
86
95
  end
87
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobbit-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Mac Adden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-06 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: coveralls
28
+ name: codeclimate-test-reporter
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: erubis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: hobbit
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: tilt
112
+ name: mote
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: erubis
126
+ name: tilt
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -142,20 +156,26 @@ files:
142
156
  - lib/hobbit/environment.rb
143
157
  - lib/hobbit/error_handling.rb
144
158
  - lib/hobbit/filter.rb
159
+ - lib/hobbit/mote.rb
145
160
  - lib/hobbit/render.rb
146
161
  - lib/hobbit/session.rb
147
162
  - spec/environment_spec.rb
148
163
  - spec/error_handling_and_filter_spec.rb
149
164
  - spec/error_handling_spec.rb
150
165
  - spec/filter_spec.rb
166
+ - spec/fixtures/mote/views/_partial.mote
167
+ - spec/fixtures/mote/views/hello.mote
168
+ - spec/fixtures/mote/views/index.mote
169
+ - spec/fixtures/mote/views/layouts/application.mote
151
170
  - spec/fixtures/render/views/_partial.erb
152
171
  - spec/fixtures/render/views/hello.erb
153
172
  - spec/fixtures/render/views/index.erb
154
173
  - spec/fixtures/render/views/layouts/application.erb
155
174
  - spec/minitest_helper.rb
175
+ - spec/mote_spec.rb
156
176
  - spec/render_spec.rb
157
177
  - spec/session_spec.rb
158
- homepage: ''
178
+ homepage: https://github.com/patriciomacadden/hobbit-contrib
159
179
  licenses:
160
180
  - MIT
161
181
  metadata: {}
@@ -175,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
195
  version: '0'
176
196
  requirements: []
177
197
  rubyforge_project:
178
- rubygems_version: 2.2.0
198
+ rubygems_version: 2.2.2
179
199
  signing_key:
180
200
  specification_version: 4
181
201
  summary: Contributed Hobbit extensions
@@ -184,10 +204,15 @@ test_files:
184
204
  - spec/error_handling_and_filter_spec.rb
185
205
  - spec/error_handling_spec.rb
186
206
  - spec/filter_spec.rb
207
+ - spec/fixtures/mote/views/_partial.mote
208
+ - spec/fixtures/mote/views/hello.mote
209
+ - spec/fixtures/mote/views/index.mote
210
+ - spec/fixtures/mote/views/layouts/application.mote
187
211
  - spec/fixtures/render/views/_partial.erb
188
212
  - spec/fixtures/render/views/hello.erb
189
213
  - spec/fixtures/render/views/index.erb
190
214
  - spec/fixtures/render/views/layouts/application.erb
191
215
  - spec/minitest_helper.rb
216
+ - spec/mote_spec.rb
192
217
  - spec/render_spec.rb
193
218
  - spec/session_spec.rb