hobbit-contrib 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 099f376fda08a626af17438fbf1e3642602ace9c
4
+ data.tar.gz: 2eb4379e2612f064b90b7d0b6d9d0d02fc043a28
5
+ SHA512:
6
+ metadata.gz: 6d571097bd56bc82f5d2602875df361b7dc00b4ac843482aa178c6ff5e0c24010ffe930eadab8b34ffeed950c7a16b833b436b513c3b55839a9539a758d8dc12
7
+ data.tar.gz: a682e80b5c624d83fda243403484dfed7837a3f0e8c834b24941b0033bedec2c0565cfc8a579f7f619c3a8cb9f9213d21a1aeed2b8220be00b934ec0f22fcca3
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - rbx-19mode
6
+ - jruby-19mode
7
+ - jruby-20mode
8
+ - jruby-head
9
+ - ruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Patricio Mac Adden
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Hobbit::Contrib
2
+
3
+ [![Build Status](https://travis-ci.org/patriciomacadden/hobbit-contrib.png?branch=master)](https://travis-ci.org/patriciomacadden/hobbit-contrib)
4
+ [![Code Climate](https://codeclimate.com/github/patriciomacadden/hobbit-contrib.png)](https://codeclimate.com/github/patriciomacadden/hobbit-contrib)
5
+
6
+ Contributed Hobbit extensions.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'hobbit-contrib', require: 'hobbit/contrib'
14
+ # or this if you want to use master
15
+ # gem 'hobbit-contrib', github: 'patriciomacadden/hobbit-contrib', require: 'hobbit/contrib'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```bash
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```bash
27
+ $ gem install hobbit-contrib
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ Each extension may have its own usage. In general, including (or extending) the
33
+ module will be enough.
34
+
35
+ ```ruby
36
+ require 'hobbit'
37
+ require 'hobbit/contrib'
38
+
39
+ class App < Hobbit::Base
40
+ # define your application
41
+ end
42
+ ```
43
+
44
+ ## Available extensions
45
+
46
+ ### Hobbit::EnhancedRender
47
+
48
+ This module extends the functionality of `Hobbit::Render`. To use this extension
49
+ just include the module:
50
+
51
+ ```ruby
52
+ require 'hobbit'
53
+ require 'hobbit/contrib'
54
+
55
+ class App < Hobbit::Base
56
+ include Hobbit::EnhancedRender
57
+
58
+ get '/' do
59
+ # index will become views/index.erb
60
+ # use a layout (named 'layout'. It will become views/layouts/layout.erb)
61
+ render 'index', {}, layout: 'layout'
62
+ end
63
+ end
64
+ ```
65
+
66
+ #### Available methods
67
+
68
+ * `template_engine`: Returns the default template engine being used for this
69
+ application. By default is `erb`.
70
+ * `layout_path`: Returns the layout path according to the given template. For
71
+ instance, `layout_path('layout')` will become `views/layouts/layout.erb`
72
+ * `view_path`: Returns the view path according to the given template. For
73
+ instance, `view_path('index')` will become `views/index.erb`
74
+ * `render`: It's the same as in `Hobbit::Render`, but you can render templates
75
+ with a layout (See the example above).
76
+ * `partial`: It's the same as `render`, but expands the template name to the
77
+ views path, except that the template name will start with an underscore. For
78
+ instance, if you call `partial 'partial'`, the path will become
79
+ `views/_partial.erb`
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create new Pull Request
88
+
89
+ ## License
90
+
91
+ See the [LICENSE](https://github.com/patriciomacadden/hobbit-contrib/blob/master/LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'spec'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hobbit/contrib/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hobbit-contrib'
8
+ spec.version = Hobbit::Contrib::VERSION
9
+ spec.authors = ['Patricio Mac Adden']
10
+ spec.email = ['patriciomacadden@gmail.com']
11
+ spec.description = %q{Contributed Hobbit extensions}
12
+ spec.summary = %q{Contributed Hobbit extensions}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'hobbit'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'minitest'
25
+ spec.add_development_dependency 'rack-test'
26
+ spec.add_development_dependency 'rake'
27
+ end
@@ -0,0 +1,5 @@
1
+ module Hobbit
2
+ module Contrib
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'hobbit/contrib/version'
2
+ require 'hobbit/enhanced_render'
@@ -0,0 +1,33 @@
1
+ require 'hobbit/render'
2
+
3
+ module Hobbit
4
+ module EnhancedRender
5
+ include Hobbit::Render
6
+
7
+ def layout_path(template)
8
+ "views/layouts/#{template}.#{template_engine}"
9
+ end
10
+
11
+ def partial(template, locals = {}, options = {}, &block)
12
+ render "_#{template}", locals, options, &block
13
+ end
14
+
15
+ def render(template, locals = {}, options = {}, &block)
16
+ template = view_path(template)
17
+ layout = options.delete(:layout)
18
+ if layout.nil?
19
+ super
20
+ else
21
+ super(layout_path layout) { super }
22
+ end
23
+ end
24
+
25
+ def template_engine
26
+ 'erb'
27
+ end
28
+
29
+ def view_path(template)
30
+ "views/#{template}.erb"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,57 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Hobbit::EnhancedRender do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ TestEnhancedRenderApp.new
8
+ end
9
+
10
+ describe '#layout_path' do
11
+ it 'must return a path' do
12
+ path = File.expand_path('../fixtures/test_enhanced_render_app/views/layouts/layout.erb', __FILE__)
13
+ app.to_app.layout_path('layout').must_equal path
14
+ end
15
+ end
16
+
17
+ describe '#partial' do
18
+ it 'must render' do
19
+ get '/partial'
20
+ last_response.must_be :ok?
21
+ last_response.body.wont_match /From layout.erb/
22
+ last_response.body.wont_match /From index.erb/
23
+ last_response.body.must_match /From _partial.erb/
24
+ end
25
+ end
26
+
27
+ describe '#render' do
28
+ it 'must render with a layout' do
29
+ get '/'
30
+ last_response.must_be :ok?
31
+ last_response.body.must_match /From layout.erb/
32
+ last_response.body.must_match /From index.erb/
33
+ last_response.body.must_match /From _partial.erb/
34
+ end
35
+
36
+ it 'must render without a layout' do
37
+ get '/without-layout'
38
+ last_response.must_be :ok?
39
+ last_response.body.wont_match /From layout.erb/
40
+ last_response.body.must_match /From index.erb/
41
+ last_response.body.must_match /From _partial.erb/
42
+ end
43
+ end
44
+
45
+ describe '#template_engine' do
46
+ it 'must be erb by default' do
47
+ app.to_app.template_engine.must_equal 'erb'
48
+ end
49
+ end
50
+
51
+ describe '#view_path' do
52
+ it 'must return a path' do
53
+ path = File.expand_path('../fixtures/test_enhanced_render_app/views/index.erb', __FILE__)
54
+ app.to_app.view_path('index').must_equal path
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ class TestEnhancedRenderApp < Hobbit::Base
2
+ include Hobbit::EnhancedRender
3
+
4
+ # we do this because it the layout path is relative to file being run
5
+ def layout_path(template)
6
+ File.expand_path("../#{super}", __FILE__)
7
+ end
8
+
9
+ # we do this because it the view path is relative to file being run
10
+ def view_path(template)
11
+ File.expand_path("../#{super}", __FILE__)
12
+ end
13
+
14
+ get '/' do
15
+ render 'index', {}, layout: 'layout'
16
+ end
17
+
18
+ get '/without-layout' do
19
+ render 'index'
20
+ end
21
+
22
+ get '/partial' do
23
+ partial 'partial'
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ <h2>From _partial.erb</h2>
@@ -0,0 +1,2 @@
1
+ <h1>From index.erb</h1>
2
+ <%= partial 'partial' %>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>From layout.erb</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,25 @@
1
+ class TestEnhancedRenderApp < Hobbit::Base
2
+ include Hobbit::EnhancedRender
3
+
4
+ # we do this because it the layout path is relative to file being run
5
+ def layout_path(template)
6
+ File.expand_path("../#{super}", __FILE__)
7
+ end
8
+
9
+ # we do this because it the view path is relative to file being run
10
+ def view_path(template)
11
+ File.expand_path("../#{super}", __FILE__)
12
+ end
13
+
14
+ get '/' do
15
+ render 'index', {}, layout: 'layout'
16
+ end
17
+
18
+ get '/without-layout' do
19
+ render 'index'
20
+ end
21
+
22
+ get '/partial' do
23
+ partial 'partial'
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+
3
+ require 'bundler'
4
+ Bundler.require :default, ENV['RACK_ENV'].to_sym
5
+
6
+ require 'minitest/autorun'
7
+ require 'rack'
8
+ require 'rack/test'
9
+
10
+ require 'hobbit'
11
+ require 'hobbit/contrib'
12
+
13
+ # hobbit test apps
14
+ require 'fixtures/test_enhanced_render_app/test_enhanced_render_app'
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hobbit-contrib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patricio Mac Adden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hobbit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Contributed Hobbit extensions
84
+ email:
85
+ - patriciomacadden@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - hobbit-contrib.gemspec
97
+ - lib/hobbit/contrib.rb
98
+ - lib/hobbit/contrib/version.rb
99
+ - lib/hobbit/enhanced_render.rb
100
+ - spec/enhanced_render_spec.rb
101
+ - spec/fixtures/test_enhanced_render_app.rb
102
+ - spec/fixtures/test_enhanced_render_app/test_enhanced_render_app.rb
103
+ - spec/fixtures/test_enhanced_render_app/views/_partial.erb
104
+ - spec/fixtures/test_enhanced_render_app/views/index.erb
105
+ - spec/fixtures/test_enhanced_render_app/views/layouts/layout.erb
106
+ - spec/minitest_helper.rb
107
+ homepage: ''
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.0.0
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Contributed Hobbit extensions
131
+ test_files:
132
+ - spec/enhanced_render_spec.rb
133
+ - spec/fixtures/test_enhanced_render_app.rb
134
+ - spec/fixtures/test_enhanced_render_app/test_enhanced_render_app.rb
135
+ - spec/fixtures/test_enhanced_render_app/views/_partial.erb
136
+ - spec/fixtures/test_enhanced_render_app/views/index.erb
137
+ - spec/fixtures/test_enhanced_render_app/views/layouts/layout.erb
138
+ - spec/minitest_helper.rb