thorero-builder 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +59 -0
- data/TODO +5 -0
- data/lib/merb-builder.rb +2 -0
- data/lib/merb-builder/template.rb +63 -0
- data/spec/builder_spec.rb +56 -0
- data/spec/controllers/builder.rb +32 -0
- data/spec/controllers/views/builder_config/index.xml.builder +4 -0
- data/spec/controllers/views/builder_controller/index.xml.builder +2 -0
- data/spec/controllers/views/capture_builder/index.xml.builder +5 -0
- data/spec/controllers/views/concat_builder/index.xml.builder +4 -0
- data/spec/controllers/views/partial_builder/_partial_builder.xml.builder +1 -0
- data/spec/controllers/views/partial_builder/index.xml.builder +2 -0
- data/spec/controllers/views/partial_ivars/_partial_builder.xml.builder +1 -0
- data/spec/controllers/views/partial_ivars/index.xml.builder +3 -0
- data/spec/spec_helper.rb +14 -0
- metadata +99 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 YOUR NAME
|
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
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require "extlib"
|
4
|
+
require 'merb-core/tasks/merb_rake_helper'
|
5
|
+
|
6
|
+
##############################################################################
|
7
|
+
# Package && release
|
8
|
+
##############################################################################
|
9
|
+
RUBY_FORGE_PROJECT = "thorero"
|
10
|
+
PROJECT_URL = "http://merbivore.com"
|
11
|
+
PROJECT_SUMMARY = "Merb plugin that provides Builder support"
|
12
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY
|
13
|
+
|
14
|
+
GEM_AUTHOR = "Jonathan Younger"
|
15
|
+
GEM_EMAIL = "jonathan@daikini.com"
|
16
|
+
|
17
|
+
GEM_NAME = "thorero-builder"
|
18
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
19
|
+
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
|
20
|
+
|
21
|
+
RELEASE_NAME = "REL #{GEM_VERSION}"
|
22
|
+
|
23
|
+
require "extlib/tasks/release"
|
24
|
+
|
25
|
+
spec = Gem::Specification.new do |s|
|
26
|
+
s.rubyforge_project = RUBY_FORGE_PROJECT
|
27
|
+
s.name = GEM_NAME
|
28
|
+
s.version = GEM_VERSION
|
29
|
+
s.platform = Gem::Platform::RUBY
|
30
|
+
s.has_rdoc = true
|
31
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
32
|
+
s.summary = PROJECT_SUMMARY
|
33
|
+
s.description = PROJECT_DESCRIPTION
|
34
|
+
s.author = GEM_AUTHOR
|
35
|
+
s.email = GEM_EMAIL
|
36
|
+
s.homepage = PROJECT_URL
|
37
|
+
s.add_dependency('merb-core', '>= 0.9.4')
|
38
|
+
s.add_dependency('builder', '>= 2.0.0')
|
39
|
+
s.require_path = 'lib'
|
40
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
44
|
+
pkg.gem_spec = spec
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Install the gem"
|
48
|
+
task :install => [:package] do
|
49
|
+
sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
|
50
|
+
end
|
51
|
+
|
52
|
+
namespace :jruby do
|
53
|
+
|
54
|
+
desc "Run :package and install the resulting .gem with jruby"
|
55
|
+
task :install => :package do
|
56
|
+
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/TODO
ADDED
data/lib/merb-builder.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Merb::Template
|
2
|
+
|
3
|
+
class Builder
|
4
|
+
|
5
|
+
# Defines a method for calling a specific Builder template.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# path<String>:: Path to the template file.
|
9
|
+
# name<~to_s>:: The name of the template method.
|
10
|
+
# mod<Class, Module>::
|
11
|
+
# The class or module wherein this method should be defined.
|
12
|
+
def self.compile_template(io, name, mod)
|
13
|
+
path = File.expand_path(io.path)
|
14
|
+
method = mod.is_a?(Module) ? :module_eval : :instance_eval
|
15
|
+
mod.send(method, %{
|
16
|
+
def #{name}
|
17
|
+
@_engine = 'builder'
|
18
|
+
config = (Merb.config[:builder] || {}).inject({}) do |c, (k, v)|
|
19
|
+
c[k.to_sym] = v
|
20
|
+
c
|
21
|
+
end
|
22
|
+
xml = ::Builder::XmlMarkup.new(config)
|
23
|
+
self.instance_eval %{#{io.read}}
|
24
|
+
xml.target!
|
25
|
+
end
|
26
|
+
})
|
27
|
+
|
28
|
+
name
|
29
|
+
end
|
30
|
+
|
31
|
+
module Mixin
|
32
|
+
def _builder_buffer(the_binding)
|
33
|
+
@_buffer = eval("xml", the_binding, __FILE__, __LINE__)
|
34
|
+
end
|
35
|
+
# ==== Parameters
|
36
|
+
# *args:: Arguments to pass to the block.
|
37
|
+
# &block:: The template block to call.
|
38
|
+
#
|
39
|
+
# ==== Returns
|
40
|
+
# String:: The output of the block.
|
41
|
+
#
|
42
|
+
# ==== Examples
|
43
|
+
# Capture being used in a .html.erb page:
|
44
|
+
#
|
45
|
+
# @foo = capture do
|
46
|
+
# xml.instruct!
|
47
|
+
# xml.foo do
|
48
|
+
# xml.bar "baz"
|
49
|
+
# end
|
50
|
+
# xml.target!
|
51
|
+
# end
|
52
|
+
def capture_builder(*args, &block)
|
53
|
+
block.call(*args)
|
54
|
+
end
|
55
|
+
|
56
|
+
def concat_builder(string, binding)
|
57
|
+
_builder_buffer(binding) << string
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
Merb::Template.register_extensions(self, %w[builder])
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Builder" do
|
4
|
+
before(:each) do
|
5
|
+
@xml = ::Builder::XmlMarkup.new :indent => 2
|
6
|
+
@xml.instruct!
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be able to render Builder templates" do
|
10
|
+
c = dispatch_to(BuilderController, :index, :format => "xml")
|
11
|
+
@xml.hello "World"
|
12
|
+
c.body.should == @xml.target!
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be able to render partial Builder templates" do
|
16
|
+
c = dispatch_to(PartialBuilder, :index, :format => "xml")
|
17
|
+
@xml.hello "World"
|
18
|
+
c.body.should == @xml.target!
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to have ivars defined in both the controller and the parent template" do
|
22
|
+
c = dispatch_to(PartialIvars, :index, :format => "xml")
|
23
|
+
@xml.p "Partial Builder"
|
24
|
+
c.body.should == @xml.target!
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should use the builder configuration in Merb::Config" do
|
28
|
+
c = dispatch_to(BuilderConfig, :index, :format => "xml")
|
29
|
+
xml = ::Builder::XmlMarkup.new :indent => 4
|
30
|
+
xml.instruct!
|
31
|
+
xml.foo do
|
32
|
+
xml.bar "baz"
|
33
|
+
end
|
34
|
+
c.body.should == xml.target!
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should capture_builder properly" do
|
38
|
+
c = dispatch_to(CaptureBuilder, :index, :format => "xml")
|
39
|
+
xml = ::Builder::XmlMarkup.new :indent => 4
|
40
|
+
xml.instruct!
|
41
|
+
xml.comment! "I would not say such things if I were you"
|
42
|
+
xml.node 'Capture'
|
43
|
+
|
44
|
+
c.body.should == xml.target!
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should concat_builder properly" do
|
48
|
+
c = dispatch_to(ConcatBuilder, :index, :format => "xml")
|
49
|
+
xml = ::Builder::XmlMarkup.new :indent => 4
|
50
|
+
xml.instruct!
|
51
|
+
xml.node 'Concat'
|
52
|
+
|
53
|
+
c.body.should == xml.target!.chomp
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class BuilderController < Merb::Controller
|
2
|
+
provides :xml
|
3
|
+
self._template_root = File.dirname(__FILE__) / "views"
|
4
|
+
def index
|
5
|
+
render
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class PartialBuilder < BuilderController
|
10
|
+
end
|
11
|
+
|
12
|
+
class BuilderConfig < BuilderController
|
13
|
+
end
|
14
|
+
|
15
|
+
class PartialIvars < BuilderController
|
16
|
+
def index
|
17
|
+
@var1 = "Partial"
|
18
|
+
render
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class CaptureBuilder < BuilderController
|
23
|
+
end
|
24
|
+
|
25
|
+
module Merb::ConcatBuilderHelper
|
26
|
+
def concatter(&blk)
|
27
|
+
concat("<node>Concat</node>", blk.binding)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ConcatBuilder < BuilderController
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
xml.hello 'World'
|
@@ -0,0 +1 @@
|
|
1
|
+
xml.p "#{@var1} #{@var2}"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$TESTING=true
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require "rubygems"
|
4
|
+
require "merb-core"
|
5
|
+
require "spec"
|
6
|
+
|
7
|
+
require "merb-builder"
|
8
|
+
require File.dirname(__FILE__) / "controllers" / "builder"
|
9
|
+
|
10
|
+
Merb.start :environment => 'test', :builder => { "indent" => 4 }
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
config.include Merb::Test::RequestHelper
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thorero-builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Younger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-02 00:00:00 +03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.4
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: builder
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0
|
34
|
+
version:
|
35
|
+
description: Merb plugin that provides Builder support
|
36
|
+
email: jonathan@daikini.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
- LICENSE
|
44
|
+
- TODO
|
45
|
+
files:
|
46
|
+
- LICENSE
|
47
|
+
- README
|
48
|
+
- Rakefile
|
49
|
+
- TODO
|
50
|
+
- lib/merb-builder
|
51
|
+
- lib/merb-builder/template.rb
|
52
|
+
- lib/merb-builder.rb
|
53
|
+
- spec/builder_spec.rb
|
54
|
+
- spec/controllers
|
55
|
+
- spec/controllers/builder.rb
|
56
|
+
- spec/controllers/views
|
57
|
+
- spec/controllers/views/builder_config
|
58
|
+
- spec/controllers/views/builder_config/index.xml.builder
|
59
|
+
- spec/controllers/views/builder_controller
|
60
|
+
- spec/controllers/views/builder_controller/index.xml.builder
|
61
|
+
- spec/controllers/views/capture_builder
|
62
|
+
- spec/controllers/views/capture_builder/index.xml.builder
|
63
|
+
- spec/controllers/views/concat_builder
|
64
|
+
- spec/controllers/views/concat_builder/index.xml.builder
|
65
|
+
- spec/controllers/views/partial_builder
|
66
|
+
- spec/controllers/views/partial_builder/_partial_builder.xml.builder
|
67
|
+
- spec/controllers/views/partial_builder/index.xml.builder
|
68
|
+
- spec/controllers/views/partial_ivars
|
69
|
+
- spec/controllers/views/partial_ivars/_partial_builder.xml.builder
|
70
|
+
- spec/controllers/views/partial_ivars/index.xml.builder
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://merbivore.com
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: thorero
|
94
|
+
rubygems_version: 1.2.0
|
95
|
+
signing_key:
|
96
|
+
specification_version: 2
|
97
|
+
summary: Merb plugin that provides Builder support
|
98
|
+
test_files: []
|
99
|
+
|