webmachine-actionview 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/Gemfile +6 -1
- data/README.md +7 -1
- data/lib/webmachine/actionview/configuration.rb +15 -2
- data/lib/webmachine/actionview/resource.rb +21 -7
- data/lib/webmachine/actionview/version.rb +1 -1
- data/spec/dummy/views/home.html.erb +3 -1
- data/spec/dummy/views/shared/_some_partial.html.erb +2 -1
- data/spec/webmachine/actionview/configuration_spec.rb +2 -0
- data/spec/webmachine/actionview/resource_spec.rb +3 -1
- data/webmachine-actionview.gemspec +3 -6
- metadata +29 -34
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup=markdown
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -61,7 +61,7 @@ Your resource itself is used as the view context. This means that you can use in
|
|
61
61
|
For example:
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
class
|
64
|
+
class CustomerResource < Webmachine::Resource
|
65
65
|
include Webmachine::ActionView::Resource
|
66
66
|
|
67
67
|
def resource_exists?
|
@@ -89,6 +89,12 @@ render partial: 'shared/my_partial'
|
|
89
89
|
Partials are subject to the same conventions as Rails, i.e. their filenames begin with an underscore, but no underscore
|
90
90
|
is required when making a call to `render partial: 'some_partial'`.
|
91
91
|
|
92
|
+
## Thanks
|
93
|
+
|
94
|
+
This gem came about a lot quicker due to someone else already having fiddled with the internals of ActionView.
|
95
|
+
The link I originally found is https://github.com/newhavenrb/conferences/wiki/Using-Rails-without-Rails, so I think
|
96
|
+
that means thanks to @drogus - pretty sure those are his slides linked to from that page.
|
97
|
+
|
92
98
|
## Contributing
|
93
99
|
|
94
100
|
1. Fork it
|
@@ -3,11 +3,18 @@ require 'active_support/configurable'
|
|
3
3
|
module Webmachine
|
4
4
|
module ActionView
|
5
5
|
|
6
|
-
# Configures settings for Webmachine::ActionView
|
6
|
+
# Configures settings for {Webmachine::ActionView}
|
7
|
+
# @return [Webmachine::ActionView::Configuration]
|
8
|
+
# @example
|
9
|
+
# Webmachine::ActionView.configure do |config|
|
10
|
+
# config.view_paths = [MY_VIEWS_PATH]
|
11
|
+
# config.handlers = [:erb, :haml, :builder]
|
12
|
+
# end
|
7
13
|
def self.configure(&block)
|
8
14
|
yield @config ||= Configuration.new
|
9
15
|
end
|
10
16
|
|
17
|
+
# @return [Webmachine::ActionView::Configuration]
|
11
18
|
def self.config
|
12
19
|
@config
|
13
20
|
end
|
@@ -15,7 +22,13 @@ module Webmachine
|
|
15
22
|
class Configuration #:nodoc:
|
16
23
|
include ActiveSupport::Configurable
|
17
24
|
|
18
|
-
|
25
|
+
DEFAULT_LAYOUT = 'layouts/application'
|
26
|
+
|
27
|
+
config_accessor :view_paths, :handlers, :default_layout
|
28
|
+
end
|
29
|
+
|
30
|
+
configure do |c|
|
31
|
+
c.default_layout = Configuration::DEFAULT_LAYOUT
|
19
32
|
end
|
20
33
|
end
|
21
34
|
end
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module Webmachine
|
2
2
|
module ActionView
|
3
|
-
|
4
|
-
[]
|
5
|
-
end
|
6
|
-
|
3
|
+
# Include on {::Webmachine::Resource}-derived classes to get access to ActionView-style templating.
|
7
4
|
module Resource
|
8
5
|
def self.included(base)
|
9
6
|
base.class_eval do
|
@@ -12,8 +9,16 @@ module Webmachine
|
|
12
9
|
end
|
13
10
|
end
|
14
11
|
|
15
|
-
|
16
|
-
|
12
|
+
# Renders a template or partial with an optional layout from a `Webmachine::ActionView::Resource`
|
13
|
+
#
|
14
|
+
# @param [Hash] options Describe what you want to render. Leave blank to render the {#default_template_name}
|
15
|
+
# @option options [String] :template Name of the template to render. Do not use with `:partial`
|
16
|
+
# @option options [String] :partial Name of the template to render. Do not use with `:template`
|
17
|
+
# @option options [String] :layout Name of the layout within which to render the template.
|
18
|
+
# @option options [String] :locals `Hash` of locals to pass to a partial.
|
19
|
+
# Defaults to {Webmachine::ActionView::Resource::DEFAULT_LAYOUT}.
|
20
|
+
# Suppress with `layout: false` or `layout: nil`
|
21
|
+
# @return [::ActionView::OutputBuffer] the output content
|
17
22
|
def render(options = nil)
|
18
23
|
options ||= default_template_name
|
19
24
|
options = { :template => options } if options.is_a?(String)
|
@@ -22,7 +27,7 @@ module Webmachine
|
|
22
27
|
if options.has_key?(:layout) && !options[:layout]
|
23
28
|
options.delete(:layout)
|
24
29
|
else
|
25
|
-
options.reverse_merge!(layout:
|
30
|
+
options.reverse_merge!(layout: Webmachine::ActionView.config.default_layout)
|
26
31
|
end
|
27
32
|
_prepare_context
|
28
33
|
end
|
@@ -30,18 +35,27 @@ module Webmachine
|
|
30
35
|
view_renderer.render(self, options)
|
31
36
|
end
|
32
37
|
|
38
|
+
# The conventional template name for the resource. In a class called `HomeResource`, this would be 'home'
|
39
|
+
#
|
40
|
+
# @return [String] default template name for this resource
|
33
41
|
def default_template_name
|
34
42
|
@default_template_name ||= self.class.name.underscore.sub(/_resource$/, '')
|
35
43
|
end
|
36
44
|
|
45
|
+
# Lazily created path set. Configure first with {::Webmachine::ActionView.configure}
|
46
|
+
# @return [::ActionView::PathSet] paths in which to find templates.
|
37
47
|
def view_paths
|
38
48
|
@view_paths ||= ::ActionView::PathSet.new(Webmachine::ActionView.config.view_paths)
|
39
49
|
end
|
40
50
|
|
51
|
+
# The `::ActionView::Context` in which views are looked up.
|
52
|
+
# @return [::ActionView::Context]
|
41
53
|
def lookup_context
|
42
54
|
@lookup_context ||= ::ActionView::LookupContext.new(view_paths)
|
43
55
|
end
|
44
56
|
|
57
|
+
# The renderer responsible for rendering when #render is called
|
58
|
+
# @return [::ActionView::Renderer] the renderer
|
45
59
|
def view_renderer
|
46
60
|
@view_renderer ||= ::ActionView::Renderer.new(lookup_context)
|
47
61
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
<p>home.html.erb content</p>
|
2
2
|
<p>id: <%= @home.id %></p>
|
3
3
|
<p>name: <%= @home.name %></p>
|
4
|
-
<div class="from_a_partial"
|
4
|
+
<div class="from_a_partial">
|
5
|
+
<%= render partial: 'shared/some_partial', locals: { local: Struct.new(:content).new(content: 'local content') } %>
|
6
|
+
</div>
|
@@ -1 +1,2 @@
|
|
1
|
-
<p>content from shared/some_partial</p>
|
1
|
+
<p>content from shared/some_partial</p>
|
2
|
+
<%= local.content %>
|
@@ -9,6 +9,7 @@ describe Webmachine::ActionView::Configuration do
|
|
9
9
|
Webmachine::ActionView.configure do |c|
|
10
10
|
c.view_paths = paths
|
11
11
|
c.handlers = handlers
|
12
|
+
c.default_layout = 'layouts/some_default'
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -16,5 +17,6 @@ describe Webmachine::ActionView::Configuration do
|
|
16
17
|
|
17
18
|
its(:view_paths) { should eql(paths) }
|
18
19
|
its(:handlers) { should eql(handlers) }
|
20
|
+
its(:default_layout) { should eql('layouts/some_default') }
|
19
21
|
end
|
20
22
|
end
|
@@ -14,9 +14,10 @@ describe "A resource including Webmachine::ActionView::Resource" do
|
|
14
14
|
let(:resource) { HomeResource.new(request, response) }
|
15
15
|
let(:unconventional_resource) { UnconventionalName.new(request, response) }
|
16
16
|
|
17
|
-
before
|
17
|
+
before do
|
18
18
|
Webmachine::ActionView.configure do |c|
|
19
19
|
c.view_paths = ['spec/dummy/views']
|
20
|
+
c.default_layout = 'layouts/application'
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
@@ -66,6 +67,7 @@ describe "A resource including Webmachine::ActionView::Resource" do
|
|
66
67
|
|
67
68
|
it { should include('content from the application layout')}
|
68
69
|
it { should include('content from shared/some_partial')}
|
70
|
+
it { should include('local content')}
|
69
71
|
end
|
70
72
|
|
71
73
|
describe "Explicit template rendering" do
|
@@ -12,12 +12,9 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = %q{Want the Rails conventions that you're used to for HTML views in webmachine-ruby? This is your gem.}
|
13
13
|
gem.homepage = "http://github.com/rgarner/webmachine-actionview"
|
14
14
|
|
15
|
-
gem.
|
16
|
-
gem.
|
17
|
-
|
18
|
-
gem.add_runtime_dependency "webmachine"
|
19
|
-
gem.add_runtime_dependency "activesupport"
|
20
|
-
gem.add_runtime_dependency "actionpack"
|
15
|
+
gem.add_dependency "webmachine", '~> 1.0'
|
16
|
+
gem.add_dependency "activesupport", '~> 3.2'
|
17
|
+
gem.add_dependency "actionpack", '~> 3.2'
|
21
18
|
|
22
19
|
gem.files = `git ls-files`.split($/)
|
23
20
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmachine-actionview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,63 +9,56 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: webmachine
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: webmachine-test
|
27
|
-
requirement: &2152312620 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - ~>
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0'
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *2152312620
|
29
|
+
version: '1.0'
|
36
30
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
39
33
|
none: false
|
40
34
|
requirements:
|
41
|
-
- -
|
35
|
+
- - ~>
|
42
36
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
37
|
+
version: '3.2'
|
44
38
|
type: :runtime
|
45
39
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: activesupport
|
49
|
-
requirement: &2152311380 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
41
|
none: false
|
51
42
|
requirements:
|
52
|
-
- -
|
43
|
+
- - ~>
|
53
44
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
type: :runtime
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *2152311380
|
45
|
+
version: '3.2'
|
58
46
|
- !ruby/object:Gem::Dependency
|
59
47
|
name: actionpack
|
60
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
61
49
|
none: false
|
62
50
|
requirements:
|
63
|
-
- -
|
51
|
+
- - ~>
|
64
52
|
- !ruby/object:Gem::Version
|
65
|
-
version: '
|
53
|
+
version: '3.2'
|
66
54
|
type: :runtime
|
67
55
|
prerelease: false
|
68
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
69
62
|
description: Brings ActionView to webmachine-ruby
|
70
63
|
email:
|
71
64
|
- rgarner@zephyros-systems.co.uk
|
@@ -74,6 +67,7 @@ extensions: []
|
|
74
67
|
extra_rdoc_files: []
|
75
68
|
files:
|
76
69
|
- .gitignore
|
70
|
+
- .yardopts
|
77
71
|
- Gemfile
|
78
72
|
- LICENSE.txt
|
79
73
|
- README.md
|
@@ -113,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
107
|
version: '0'
|
114
108
|
requirements: []
|
115
109
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.8.
|
110
|
+
rubygems_version: 1.8.25
|
117
111
|
signing_key:
|
118
112
|
specification_version: 3
|
119
113
|
summary: Want the Rails conventions that you're used to for HTML views in webmachine-ruby?
|
@@ -129,3 +123,4 @@ test_files:
|
|
129
123
|
- spec/spec_helper.rb
|
130
124
|
- spec/webmachine/actionview/configuration_spec.rb
|
131
125
|
- spec/webmachine/actionview/resource_spec.rb
|
126
|
+
has_rdoc:
|