inline_view_template 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in inline_view_template.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,89 @@
1
+ = InlineViewTemplate
2
+
3
+ Inline view templates are used to define reusable markup in Rails without
4
+ defining a separate partial view template. They can be used to define inline
5
+ partials or even inline layout templates.
6
+
7
+ Inline view templates are useful when there are sections of markup that are
8
+ shared among several sections within a view template, yet may not be
9
+ substantial enough to merit their own partial view template.
10
+
11
+ In addition, inline view templates can be treated as objects that can be passed
12
+ around to other view templates (whether inline or regular) for rendering within
13
+ those templates.
14
+
15
+ If a content block is specified when calling +#render+, it will be passed
16
+ through as an inline view template in the last parameter to the content block
17
+ with which the inline view template was initialized. In effect, the inline view
18
+ view template can serve as an inline layout template for the content specified
19
+ to +#render+.
20
+
21
+ == Installation
22
+
23
+ Add the +inline_view_template+ gem to your project. If you use bundler, this
24
+ is done by adding an entry in your project's +Gemfile+.
25
+
26
+ == Examples
27
+
28
+ === Serving as a partial template
29
+
30
+ ==== Using ERb
31
+
32
+ <% table_row_template = InlineViewTemplate.new do |attr, value| %>
33
+ <tr>
34
+ <th><%= attr %></th>
35
+ <td><%= value %></td>
36
+ </tr>
37
+ <% end %>
38
+
39
+ <table><tbody>
40
+ <% @user.attributes.each do |attr, value| %>
41
+ <%= table_row_template.render(attr, value) %>
42
+ <% end %>
43
+ </tbody></table>
44
+
45
+ ==== Using HAML
46
+
47
+ - table_row_template = InlineViewTemplate.new do |attr, value|
48
+ %tr
49
+ %th= attr
50
+ %td= value
51
+
52
+ %table
53
+ %tbody
54
+ - @user.attributes.each do |attr, value|
55
+ = table_row_template.render(attr, value)
56
+
57
+ === Serving as a layout template
58
+
59
+ ==== Using ERb
60
+
61
+ <% form_layout = InlineViewTemplate.new do |user, form_fields| %>
62
+ <% form_for user do |form| %>
63
+ <%= form_fields.render(form) %>
64
+ <%= form.submit %>
65
+ <% end %>
66
+ <% end %>
67
+
68
+ <%= form_layout.render(@user) do |form| %>
69
+ <p>Name: <%= form.text_field :name %></p>
70
+ <p>Address: <%= form.text_field :address %></p>
71
+ <% end %>
72
+
73
+ ==== Using HAML
74
+
75
+ - form_layout = InlineViewTemplate.new do |user, form_fields|
76
+ - form_for user do |form|
77
+ = form_fields.render(form)
78
+ = form.submit
79
+
80
+ = form_layout.render(@user) do |form|
81
+ %p
82
+ Name:
83
+ = form.text_field :name
84
+ %p
85
+ Address:
86
+ = form.text_field :address
87
+
88
+ Author:: Clyde Law (mailto:claw@alum.mit.edu)
89
+ License:: Released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "inline_view_template/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "inline_view_template"
7
+ s.version = InlineViewTemplate::VERSION
8
+ s.authors = ["Clyde Law"]
9
+ s.email = ["claw@alum.mit.edu"]
10
+ s.homepage = %q{http://github.com/Umofomia/inline_view_template}
11
+ s.summary = %q{Inline view templates are used to define reusable markup in Rails without defining a separate partial view template.}
12
+ s.description = %q{Inline view templates are used to define reusable markup in Rails without defining a separate partial view template. They can be used to define inline partials or even inline layout templates.}
13
+ s.license = 'MIT'
14
+
15
+ s.add_dependency('actionpack')
16
+
17
+ s.rubyforge_project = "inline_view_template"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,24 @@
1
+ require "inline_view_template/version"
2
+
3
+ class InlineViewTemplate
4
+
5
+ def initialize(&contents)
6
+ raise ArgumentError.new('missing content block') unless block_given?
7
+ @contents = contents
8
+
9
+ # Get the scope of the view in which the template is defined so that
10
+ # ActionView::Helpers::CaptureHelper#capture can later be called from it in
11
+ # order to render the template.
12
+ @view_scope = eval('self', contents.binding)
13
+ end
14
+
15
+ def render(*args, &sub_contents)
16
+ # If a content block was specified, create an inline view template out of
17
+ # it to pass through as the last parameter to this inline view template.
18
+ args << self.class.new(&sub_contents) if block_given?
19
+
20
+ # Render the inline view template.
21
+ @view_scope.capture(*args, &@contents)
22
+ end
23
+
24
+ end
@@ -0,0 +1,3 @@
1
+ class InlineViewTemplate
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inline_view_template
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Clyde Law
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-10-01 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: actionpack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Inline view templates are used to define reusable markup in Rails without defining a separate partial view template. They can be used to define inline partials or even inline layout templates.
36
+ email:
37
+ - claw@alum.mit.edu
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - README.rdoc
48
+ - Rakefile
49
+ - inline_view_template.gemspec
50
+ - lib/inline_view_template.rb
51
+ - lib/inline_view_template/version.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/Umofomia/inline_view_template
54
+ licenses:
55
+ - MIT
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: inline_view_template
82
+ rubygems_version: 1.6.2
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Inline view templates are used to define reusable markup in Rails without defining a separate partial view template.
86
+ test_files: []
87
+