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 +4 -4
- data/.travis.yml +4 -0
- data/CHANGELOG.md +4 -0
- data/README.md +34 -1
- data/hobbit-contrib.gemspec +4 -3
- data/lib/hobbit/contrib.rb +1 -0
- data/lib/hobbit/contrib/version.rb +1 -1
- data/lib/hobbit/mote.rb +44 -0
- data/lib/hobbit/render.rb +1 -2
- data/spec/environment_spec.rb +1 -1
- data/spec/error_handling_and_filter_spec.rb +4 -4
- data/spec/error_handling_spec.rb +1 -1
- data/spec/filter_spec.rb +29 -2
- data/spec/fixtures/mote/views/_partial.mote +5 -0
- data/spec/fixtures/mote/views/hello.mote +5 -0
- data/spec/fixtures/mote/views/index.mote +1 -0
- data/spec/fixtures/mote/views/layouts/application.mote +9 -0
- data/spec/minitest_helper.rb +3 -3
- data/spec/mote_spec.rb +89 -0
- data/spec/render_spec.rb +9 -0
- metadata +32 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7605fffd9d4c2602f35c6556529d11bafb64883
|
4
|
+
data.tar.gz: 58af370162d53892f0f966e18b0fd8daaf49c1e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ccf2711a81fd56a5405cf9989843263261a8436d40e984b23e5b9500a3591f9a73dc25d597cb91507e847bfaeecb3f47b2903181b975a663cb17755f624d684
|
7
|
+
data.tar.gz: 239c9527fbdd4485e311414b319f75d7ba8764e64368dd28f72daafeb8c6449b5348ba0079f3335393cb1cb62aae3820bfb3e271bbe5876a07aacd374874b1ed
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Hobbit::Contrib [![Build Status](
|
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
|
data/hobbit-contrib.gemspec
CHANGED
@@ -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 '
|
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
|
data/lib/hobbit/contrib.rb
CHANGED
data/lib/hobbit/mote.rb
ADDED
@@ -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
|
27
|
-
options.delete :layout
|
26
|
+
layout = options.delete :layout
|
28
27
|
end
|
29
28
|
if layout
|
30
29
|
_render(layout) { _render(template) }
|
data/spec/environment_spec.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
109
|
+
let :app do
|
110
110
|
mock_app do
|
111
111
|
include Hobbit::ErrorHandling
|
112
112
|
include Hobbit::Filter
|
data/spec/error_handling_spec.rb
CHANGED
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
|
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
|
141
|
+
let :app do
|
115
142
|
mock_app do
|
116
143
|
include Hobbit::Filter
|
117
144
|
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Hello World!</h1>
|
data/spec/minitest_helper.rb
CHANGED
@@ -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.
|
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
|
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:
|
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:
|
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:
|
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.
|
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
|