erbextensions 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/LICENSE +20 -0
- data/Manifest.txt +11 -0
- data/README.txt +120 -0
- data/Rakefile +15 -0
- data/examples/template.erb +9 -0
- data/examples/template_wrapper.erb +16 -0
- data/lib/erbextensions.rb +37 -0
- data/test/test.erb +9 -0
- data/test/test2.erb +1 -0
- data/test/test_erbextensions.rb +17 -0
- metadata +76 -0
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Designing Patterns
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
= erbextensions
|
2
|
+
* Project Page: http://rubyforge.org/projects/erbextensions/
|
3
|
+
* Documentation: http://erbextensions.rubyforge.org/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
This package enhances the Standard ERB library, including providing:
|
7
|
+
* A method for returning the processed contents of a named erb file
|
8
|
+
(ERB.process_file). This makes it very easy to include one erb file
|
9
|
+
within another erb file.
|
10
|
+
|
11
|
+
== PROBLEMS:
|
12
|
+
None (known).
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
======+examples/template_wrapper.erb+:
|
16
|
+
<%=
|
17
|
+
require 'rubygems'
|
18
|
+
require 'erbextensions'
|
19
|
+
|
20
|
+
$recipient = "Dr. Frankenstein"
|
21
|
+
$position = "assistant"
|
22
|
+
$source = "Mad Scientist Monthly"
|
23
|
+
$field = "resurrection science"
|
24
|
+
$skill = "restraining experimental subjects"
|
25
|
+
|
26
|
+
#
|
27
|
+
# This call would be much cleaner with the 'relative' gem:
|
28
|
+
# ERB::process_file(PathRelativeToCaller.new("template.erb"))
|
29
|
+
#
|
30
|
+
ERB::process_file(File.join(File.dirname(__FILE__), "template.erb"))
|
31
|
+
%>
|
32
|
+
|
33
|
+
======+examples/template.erb+:
|
34
|
+
Dear <%= $recipient %>,
|
35
|
+
I am writing to be considered for the <%= $position %> position that
|
36
|
+
you recently advertised in <%= $source %>. I possess a keen interest
|
37
|
+
in <%= $field %> and am eager to apply my deep skills in
|
38
|
+
<%= $skill %>. I have enclosed my resume for
|
39
|
+
your consideration.
|
40
|
+
|
41
|
+
Sincerely,
|
42
|
+
Igor
|
43
|
+
|
44
|
+
The example consists of a cover letter that is templated on a few variables
|
45
|
+
in order to adjust the letter's pitch to match the job being sought.
|
46
|
+
After the template variables are initialized in +template_wrapper.erb+, an
|
47
|
+
ERB.process_file call includes the expanded contents of +template.erb+.
|
48
|
+
On the command line, run:
|
49
|
+
erb examples/template_wrapper.erb
|
50
|
+
to produce:
|
51
|
+
======The output of <code>erb examples/template_wrapper.erb</code>:
|
52
|
+
Dear Dr. Frankenstein,
|
53
|
+
I am writing to be considered for the assistant position that
|
54
|
+
you recently advertised in Mad Scientist Monthly. I possess a keen interest
|
55
|
+
in resurrection science and am eager to apply my deep skills in
|
56
|
+
restraining experimental subjects. I have enclosed my resume for
|
57
|
+
your consideration.
|
58
|
+
|
59
|
+
Sincerely,
|
60
|
+
Igor
|
61
|
+
|
62
|
+
== RECOMMENDED
|
63
|
+
This gem best is used with the relative gem (http://relative.rubyforge.org).
|
64
|
+
The relative gem upgrades the Ruby core and standard libraries to handle
|
65
|
+
paths relative to source files, which makes referencing a file within an erb
|
66
|
+
file much easier (see the comment in +examples/template_wrapper.erb+ for
|
67
|
+
a demonstration)
|
68
|
+
|
69
|
+
== REQUIREMENTS:
|
70
|
+
Hoe is required but only for running the tests.
|
71
|
+
|
72
|
+
== INSTALL:
|
73
|
+
sudo gem install erbextensions
|
74
|
+
|
75
|
+
== AUTHORS:
|
76
|
+
=== Designing Patterns
|
77
|
+
* Homepage: http://www.designingpatterns.com
|
78
|
+
* Blogs: http://blogs.designingpatterns.com
|
79
|
+
|
80
|
+
== SUPPORT
|
81
|
+
Please post questions, concerns, or requests for enhancement to the forums on
|
82
|
+
the project page. Alternatively, direct contact information for
|
83
|
+
Designing Patterns can be found on the project page for this gem.
|
84
|
+
|
85
|
+
== ENHANCEMENTS
|
86
|
+
Please feel free to contact us with any ideas; we will try our best to
|
87
|
+
enhance the software and respond to user requests. Of course, we are more
|
88
|
+
likely to work on a particular enhancement if we know that there are users
|
89
|
+
who want it. Designing Patterns provides contracting and consulting services,
|
90
|
+
so if there is an enhancement that *must* get done (and in a specified time
|
91
|
+
frame), please inquire about retaining our services!
|
92
|
+
|
93
|
+
== LICENSE:
|
94
|
+
The license text can be found in the +LICENSE+ file at the root of the
|
95
|
+
distribution.
|
96
|
+
|
97
|
+
This package is licensed with an MIT license:
|
98
|
+
|
99
|
+
Copyright (c) 2008 Designing Patterns
|
100
|
+
|
101
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
102
|
+
a copy of this software and associated documentation files (the
|
103
|
+
'Software'), to deal in the Software without restriction, including
|
104
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
105
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
106
|
+
permit persons to whom the Software is furnished to do so, subject to
|
107
|
+
the following conditions:
|
108
|
+
|
109
|
+
The above copyright notice and this permission notice shall be
|
110
|
+
included in all copies or substantial portions of the Software.
|
111
|
+
|
112
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
113
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
114
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
115
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
116
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
117
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
118
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
119
|
+
|
120
|
+
== SHARE AND ENJOY!
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift("lib")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'hoe'
|
7
|
+
|
8
|
+
$stderr = STDERR
|
9
|
+
|
10
|
+
Hoe.new('erbextensions', "1.0.0") do |p|
|
11
|
+
p.remote_rdoc_dir = ''
|
12
|
+
p.developer('DesigningPatterns', 'technical.inquiries@designingpatterns.com')
|
13
|
+
end
|
14
|
+
|
15
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Dear <%= $recipient %>,
|
2
|
+
I am writing to be considered for the <%= $position %> position that
|
3
|
+
you recently advertised in <%= $source %>. I possess a keen interest
|
4
|
+
in <%= $field %> and am eager to apply my deep skills in
|
5
|
+
<%= $skill %>. I have enclosed my resume for
|
6
|
+
your consideration.
|
7
|
+
|
8
|
+
Sincerely,
|
9
|
+
Igor
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%=
|
2
|
+
require 'rubygems'
|
3
|
+
require 'erbextensions'
|
4
|
+
|
5
|
+
$recipient = "Dr. Frankenstein"
|
6
|
+
$position = "assistant"
|
7
|
+
$source = "Mad Scientist Monthly"
|
8
|
+
$field = "resurrection science"
|
9
|
+
$skill = "restraining experimental subjects"
|
10
|
+
|
11
|
+
#
|
12
|
+
# This call would be much cleaner with the 'relative' gem:
|
13
|
+
# ERB::process_file(PathRelativeToCaller.new("template.erb"))
|
14
|
+
#
|
15
|
+
ERB::process_file(File.join(File.dirname(__FILE__), "template.erb"))
|
16
|
+
%>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class ERB
|
4
|
+
#
|
5
|
+
# ====Description:
|
6
|
+
# This method returns the contents of file_name, after expanding
|
7
|
+
# all embedded Ruby in the file with ERB. This can be used to
|
8
|
+
# "include" an erb file from within another erb file.
|
9
|
+
#
|
10
|
+
# ====Parameters:
|
11
|
+
# [file_name]
|
12
|
+
# The name of the file to process
|
13
|
+
#
|
14
|
+
# ====Returns:
|
15
|
+
# The contents of file_name, after expanding all embedded Ruby in the
|
16
|
+
# file with ERB.
|
17
|
+
#
|
18
|
+
def self.process_file(file_name)
|
19
|
+
#
|
20
|
+
# ERB does not handle being invoked from within an ERB instance well.
|
21
|
+
# In order to make this work,
|
22
|
+
# 1.) Pass binding() into result(), in order that the new ERB
|
23
|
+
# instance will create a local variable binding for 'erbout'
|
24
|
+
# rather than using a top-level binding (which would lead to its
|
25
|
+
# clearing any existing text already expanded by ancestor ERB
|
26
|
+
# instances). This also could be accomplished by using a
|
27
|
+
# unique name instead of 'erbout' (something like Common LISP's
|
28
|
+
# gensym).
|
29
|
+
# 2.) Set erb's filename member, so that paths relative to calling files
|
30
|
+
# (the relative gem) will work properly; this also ensures that
|
31
|
+
# stack trace looks reasonable.
|
32
|
+
#
|
33
|
+
erb = ERB.new(IO.read(file_name), nil, nil, 'erbout')
|
34
|
+
erb.filename = file_name
|
35
|
+
return erb.result(binding())
|
36
|
+
end
|
37
|
+
end
|
data/test/test.erb
ADDED
data/test/test2.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<%= (0..10).map { |value| "#{value}" }.join(" ") %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'erbextensions'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class ERBExtensionsTest < Test::Unit::TestCase
|
8
|
+
def test_process_file
|
9
|
+
expected_contents = ""
|
10
|
+
expected_contents << "Hello, world!\n\n"
|
11
|
+
expected_contents << "0 1 2 3 4 5 6 7 8 9 10\n\n\n"
|
12
|
+
expected_contents << "Goodbye!\n"
|
13
|
+
|
14
|
+
assert_equal(expected_contents,
|
15
|
+
ERB::process_file(File.join(File.dirname(__FILE__), 'test.erb')))
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erbextensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DesigningPatterns
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-27 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.0
|
24
|
+
version:
|
25
|
+
description: "This package enhances the Standard ERB library, including providing: * A method for returning the processed contents of a named erb file (ERB.process_file). This makes it very easy to include one erb file within another erb file."
|
26
|
+
email:
|
27
|
+
- technical.inquiries@designingpatterns.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- Manifest.txt
|
34
|
+
- History.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- Manifest.txt
|
38
|
+
- LICENSE
|
39
|
+
- History.txt
|
40
|
+
- README.txt
|
41
|
+
- Rakefile
|
42
|
+
- examples/template.erb
|
43
|
+
- examples/template_wrapper.erb
|
44
|
+
- lib/erbextensions.rb
|
45
|
+
- test/test_erbextensions.rb
|
46
|
+
- test/test2.erb
|
47
|
+
- test/test.erb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: "Project Page: http://rubyforge.org/projects/erbextensions/"
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --main
|
53
|
+
- README.txt
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: erbextensions
|
71
|
+
rubygems_version: 1.2.0
|
72
|
+
signing_key:
|
73
|
+
specification_version: 2
|
74
|
+
summary: "This package enhances the Standard ERB library, including providing: * A method for returning the processed contents of a named erb file (ERB.process_file)"
|
75
|
+
test_files:
|
76
|
+
- test/test_erbextensions.rb
|