Capcode 0.8.9 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -1
- data/doc/rdoc/classes/Capcode.html +410 -545
- data/doc/rdoc/classes/Capcode/Configuration.html +263 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +154 -345
- data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +6 -6
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +42 -2
- data/doc/rdoc/files/lib/capcode/configuration_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/text_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode_rb.html +14 -1
- data/doc/rdoc/fr_class_index.html +1 -1
- data/doc/rdoc/fr_file_index.html +0 -13
- data/doc/rdoc/fr_method_index.html +12 -14
- data/examples/render-image.rb +1 -1
- data/examples/render-text.rb +4 -1
- data/examples/rest.rb +1 -0
- data/examples/sample.rb +5 -3
- data/examples/upload.rb +1 -0
- data/lib/capcode.rb +45 -61
- data/lib/capcode/configuration.rb +69 -34
- data/lib/capcode/render/text.rb +1 -1
- data/lib/capcode/version.rb +1 -1
- metadata +31 -106
- data/doc/rdoc/classes/Capcode/Mab.html +0 -118
- data/doc/rdoc/files/lib/capcode/render/binary_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/email_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/erb_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/haml_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/json_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/mustache_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/none_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/redirect_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/sass_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/static_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +0 -124
- data/doc/rdoc/files/lib/capcode/render/xml_rb.html +0 -101
- data/examples/auth-webdav.rb +0 -29
- data/examples/blog-ar.rb +0 -81
- data/examples/blog-ar.yml +0 -3
- data/examples/blog-couchdb-run.rb +0 -10
- data/examples/blog-couchdb.rb +0 -314
- data/examples/blog-couchdb.ru +0 -12
- data/examples/blog-couchdb.yml +0 -2
- data/examples/blog-dm.rb +0 -63
- data/examples/blog-dm.yml +0 -2
- data/examples/blog-mongodb-run.rb +0 -10
- data/examples/blog-mongodb.rb +0 -304
- data/examples/blog-mongodb.yml +0 -3
- data/examples/blog-sq.rb +0 -82
- data/examples/blog-sq.yml +0 -3
- data/examples/mail/mail_html.rhtml +0 -1
- data/examples/mail/mail_text.rhtml +0 -1
- data/examples/mail/ok.rhtml +0 -1
- data/examples/mail/rubyfr.png +0 -0
- data/examples/mustache/with_class.mustache +0 -8
- data/examples/mustache/without_class.mustache +0 -1
- data/examples/render-binary.rb +0 -46
- data/examples/render-email.rb +0 -68
- data/examples/render-erb.rb +0 -19
- data/examples/render-haml_sass.rb +0 -26
- data/examples/render-json.rb +0 -13
- data/examples/render-markaby.rb +0 -29
- data/examples/render-mustache.rb +0 -30
- data/examples/render-redirect.rb +0 -19
- data/examples/render-static.rb +0 -21
- data/examples/render-static.ru +0 -19
- data/examples/render-use.rb +0 -32
- data/examples/render-webdav.rb +0 -26
- data/examples/render-xml.rb +0 -24
- data/examples/rss.rb +0 -48
- data/examples/static/coderay.css +0 -131
- data/examples/static/index.html +0 -24
- data/examples/test/index.html +0 -1
- data/lib/capcode/base/ar.rb +0 -54
- data/lib/capcode/base/couchdb.rb +0 -23
- data/lib/capcode/base/dm.rb +0 -33
- data/lib/capcode/base/mongodb.rb +0 -27
- data/lib/capcode/base/sq.rb +0 -58
- data/lib/capcode/render/binary.rb +0 -8
- data/lib/capcode/render/email.rb +0 -73
- data/lib/capcode/render/erb.rb +0 -59
- data/lib/capcode/render/haml.rb +0 -60
- data/lib/capcode/render/json.rb +0 -14
- data/lib/capcode/render/markaby.rb +0 -38
- data/lib/capcode/render/mustache.rb +0 -37
- data/lib/capcode/render/none.rb +0 -7
- data/lib/capcode/render/redirect.rb +0 -7
- data/lib/capcode/render/sass.rb +0 -48
- data/lib/capcode/render/static.rb +0 -14
- data/lib/capcode/render/webdav.rb +0 -49
- data/lib/capcode/render/xml.rb +0 -119
data/lib/capcode/render/email.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'mail'
|
3
|
-
rescue LoadError => e
|
4
|
-
raise MissingLibrary, "mail could not be loaded (is it installed?): #{e.message}"
|
5
|
-
end
|
6
|
-
|
7
|
-
module Capcode
|
8
|
-
module Helpers
|
9
|
-
def render_email( f, _ ) #:nodoc:
|
10
|
-
if @smtp.nil?
|
11
|
-
@smtp = { :server => "127.0.0.1", :port => 25 }.merge(Capcode.get( :smtp ) || {})
|
12
|
-
end
|
13
|
-
|
14
|
-
# Set SMTP info
|
15
|
-
conf = Mail::Configuration.instance.defaults
|
16
|
-
conf.smtp @smtp[:server], @smtp[:port]
|
17
|
-
|
18
|
-
# Create mail
|
19
|
-
mail = Mail.new()
|
20
|
-
|
21
|
-
# Mail Header
|
22
|
-
mail.from = f[:from]
|
23
|
-
mail.subject = f[:subject] if f.has_key?(:subject)
|
24
|
-
[:to, :cc, :bcc].each do |t|
|
25
|
-
next unless f.has_key?(t) and not f[t].nil?
|
26
|
-
if f[t].class == Array
|
27
|
-
mail[t] = f[t]
|
28
|
-
else
|
29
|
-
mail[t] = f[t].to_s.split( ',' ).map { |x| x.strip }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
mail.message_id = f[:message_id] if f.has_key?(:message_id)
|
33
|
-
|
34
|
-
# Mail Body
|
35
|
-
if f[:body].class == String
|
36
|
-
mail.body = f[:body]
|
37
|
-
elsif f[:body].class == Hash
|
38
|
-
if f[:body].has_key?(:html)
|
39
|
-
mail.html_part = Mail::Part.new
|
40
|
-
mail.html_part.content_type = f[:body][:html].delete(:content_type) { |_| 'text/html' }
|
41
|
-
mail.html_part.body = render( f[:body][:html] )
|
42
|
-
end
|
43
|
-
if f[:body].has_key?(:text)
|
44
|
-
mail.text_part = Mail::Part.new
|
45
|
-
mail.text_part.body = render( f[:body][:text] )
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Mail Attachment
|
50
|
-
if f.has_key?(:file)
|
51
|
-
f[:file] = [f[:file]] unless f[:file].class == Array
|
52
|
-
f[:file].each do |file|
|
53
|
-
data = {}
|
54
|
-
if file.class == Hash
|
55
|
-
data[:filename] = file.delete(:filename) if file.has_key?(:filename)
|
56
|
-
data[:mime_type] = file.delete(:mime_type) if file.has_key?(:mime_type)
|
57
|
-
data[:data] = self.send(file[:data])
|
58
|
-
else
|
59
|
-
data = { :data => render( :static => file, :exact_path => false ), :filename => File.basename(file) }
|
60
|
-
end
|
61
|
-
mail.add_file(data)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
begin
|
66
|
-
mail.deliver!
|
67
|
-
render f[:ok]
|
68
|
-
rescue
|
69
|
-
render f[:error]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/lib/capcode/render/erb.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module Capcode
|
4
|
-
module Helpers
|
5
|
-
# Set the path to ERB files. If this path is not set, Capcode will search in the static path.
|
6
|
-
# This method is deprecated and will be removed in version 1.0
|
7
|
-
def self.erb_path=( p )
|
8
|
-
warn "Capcode::Helpers.erb_path is deprecated and will be removed in version 1.0, please use `set :erb'"
|
9
|
-
Capcode.set :erb, p
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_binding #:nodoc:
|
13
|
-
binding
|
14
|
-
end
|
15
|
-
|
16
|
-
def render_erb( f, opts ) #:nodoc:
|
17
|
-
if @erb_path.nil?
|
18
|
-
@erb_path = Capcode.get( :erb ) || Capcode.static()
|
19
|
-
end
|
20
|
-
|
21
|
-
f = f.to_s
|
22
|
-
if f.include? '..'
|
23
|
-
return [403, {}, '403 - Invalid path']
|
24
|
-
end
|
25
|
-
|
26
|
-
if /Windows/.match( ENV['OS'] )
|
27
|
-
unless( /.:\\/.match( @erb_path[0] ) )
|
28
|
-
@erb_path = File.expand_path( File.join(".", @erb_path) )
|
29
|
-
end
|
30
|
-
else
|
31
|
-
unless( @erb_path[0].chr == "/" )
|
32
|
-
@erb_path = File.expand_path( File.join(".", @erb_path) )
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Get Layout
|
37
|
-
layout = opts.delete(:layout)||:layout
|
38
|
-
layout_file = File.join( @erb_path, layout.to_s+".rhtml" )
|
39
|
-
|
40
|
-
# Get file
|
41
|
-
f = f + ".rhtml" if File.extname( f ) != ".rhtml"
|
42
|
-
file = File.join( @erb_path, f )
|
43
|
-
|
44
|
-
if( File.exist?( file ) )
|
45
|
-
if( File.exist?( layout_file ) )
|
46
|
-
ERB.new(open(layout_file).read).result( get_binding { |*args|
|
47
|
-
#@@__ARGS__ = args
|
48
|
-
Capcode::Helpers.args = args
|
49
|
-
ERB.new(open(file).read).result(binding)
|
50
|
-
} )
|
51
|
-
else
|
52
|
-
ERB.new(open(file).read).result(binding)
|
53
|
-
end
|
54
|
-
else
|
55
|
-
raise Capcode::RenderError, "Error rendering `erb', #{file} does not exist !"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/lib/capcode/render/haml.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'haml'
|
3
|
-
rescue LoadError => e
|
4
|
-
raise MissingLibrary, "Haml could not be loaded (is it installed?): #{e.message}"
|
5
|
-
end
|
6
|
-
|
7
|
-
module Capcode
|
8
|
-
module Helpers
|
9
|
-
# Set the path to Haml files. If this path is not set, Capcode will search in the static path.
|
10
|
-
# This method is deprecated and will be removed in version 1.0
|
11
|
-
def self.haml_path=( p )
|
12
|
-
warn "Capcode::Helpers.haml_path is deprecated and will be removed in version 1.0, please use `set :haml'"
|
13
|
-
Capcode.set :haml, p
|
14
|
-
end
|
15
|
-
|
16
|
-
def render_haml( f, opts ) #:nodoc:
|
17
|
-
if @haml_path.nil?
|
18
|
-
@haml_path = Capcode.get( :haml ) || Capcode.static()
|
19
|
-
end
|
20
|
-
|
21
|
-
f = f.to_s
|
22
|
-
if f.include? '..'
|
23
|
-
return [403, {}, '403 - Invalid path']
|
24
|
-
end
|
25
|
-
|
26
|
-
if /Windows/.match( ENV['OS'] )
|
27
|
-
unless( /.:\\/.match( @haml_path[0] ) )
|
28
|
-
@haml_path = File.expand_path( File.join(".", @haml_path) )
|
29
|
-
end
|
30
|
-
else
|
31
|
-
unless( @haml_path[0].chr == "/" )
|
32
|
-
@haml_path = File.expand_path( File.join(".", @haml_path) )
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Get Layout file
|
37
|
-
layout = opts.delete(:layout)||:layout
|
38
|
-
layout_file = File.join( @haml_path, layout.to_s+".haml" )
|
39
|
-
|
40
|
-
# Get HAML File
|
41
|
-
f = f + ".haml" if File.extname( f ) != ".haml"
|
42
|
-
file = File.join( @haml_path, f )
|
43
|
-
|
44
|
-
# Render
|
45
|
-
if( File.exist?( file ) )
|
46
|
-
if( File.exist?( layout_file ) )
|
47
|
-
Haml::Engine.new( open( layout_file ).read ).to_html(self) { |*args|
|
48
|
-
#@@__ARGS__ = args
|
49
|
-
Capcode::Helpers.args = args
|
50
|
-
Haml::Engine.new( open( file ).read ).render(self)
|
51
|
-
}
|
52
|
-
else
|
53
|
-
Haml::Engine.new( open( file ).read ).to_html( self )
|
54
|
-
end
|
55
|
-
else
|
56
|
-
raise Capcode::RenderError, "Error rendering `haml', #{file} does not exist !"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/capcode/render/json.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'json'
|
3
|
-
rescue LoadError => e
|
4
|
-
raise MissingLibrary, "Json could not be loaded (is it installed?): #{e.message}"
|
5
|
-
end
|
6
|
-
|
7
|
-
module Capcode
|
8
|
-
module Helpers
|
9
|
-
def render_json( f, opts ) #:nodoc:
|
10
|
-
@response['Content-Type'] = 'application/json'
|
11
|
-
f.to_json
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'markaby'
|
3
|
-
rescue LoadError => e
|
4
|
-
raise MissingLibrary, "Markaby could not be loaded (is it installed?): #{e.message}"
|
5
|
-
end
|
6
|
-
|
7
|
-
Markaby::Builder.set(:indent, 2)
|
8
|
-
|
9
|
-
module Capcode
|
10
|
-
class Mab < Markaby::Builder
|
11
|
-
include Views
|
12
|
-
end
|
13
|
-
|
14
|
-
module Helpers
|
15
|
-
def render_markaby( f, opts ) #:nodoc:
|
16
|
-
f = f.to_s
|
17
|
-
layout = opts.delete(:layout)||:layout
|
18
|
-
|
19
|
-
assigns = {}
|
20
|
-
self.instance_variables.delete_if {|x| ["@response", "@env", "@request"].include?(x) }.each do |ivar|
|
21
|
-
assigns[ivar.gsub( /^@/, "" )] = self.instance_variable_get(ivar)
|
22
|
-
end
|
23
|
-
|
24
|
-
__mab = Mab.new(assigns.merge( opts ), self) {
|
25
|
-
if self.respond_to?(layout)
|
26
|
-
self.send(layout.to_s) { |*args|
|
27
|
-
# @@__ARGS__ = args
|
28
|
-
Capcode::Helpers.args = args
|
29
|
-
self.send(f)
|
30
|
-
}
|
31
|
-
else
|
32
|
-
self.send(f)
|
33
|
-
end
|
34
|
-
}
|
35
|
-
__mab.to_s
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'mustache'
|
3
|
-
rescue LoadError => e
|
4
|
-
raise MissingLibrary, "Mustache could not be loaded (is it installed?): #{e.message}"
|
5
|
-
end
|
6
|
-
|
7
|
-
module Capcode
|
8
|
-
module Helpers
|
9
|
-
def render_mustache( f, opts ) #:nodoc:
|
10
|
-
mustache_path = Capcode.get( :mustache ) || Capcode.static()
|
11
|
-
|
12
|
-
name = Mustache.classify(f.to_s)
|
13
|
-
|
14
|
-
if Capcode::Views.const_defined?(name)
|
15
|
-
klass = Capcode::Views.const_get(name)
|
16
|
-
else
|
17
|
-
klass = Mustache
|
18
|
-
klass.template_file = mustache_path + "/" + f.to_s + ".mustache"
|
19
|
-
end
|
20
|
-
|
21
|
-
klass.template_extension = 'mustache'
|
22
|
-
klass.template_path = mustache_path
|
23
|
-
|
24
|
-
instance = klass.new
|
25
|
-
|
26
|
-
instance_variables.each do |name|
|
27
|
-
instance.instance_variable_set(name, instance_variable_get(name))
|
28
|
-
end
|
29
|
-
|
30
|
-
opts.each do |k, v|
|
31
|
-
instance[k] = v
|
32
|
-
end
|
33
|
-
|
34
|
-
instance.to_html
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/capcode/render/none.rb
DELETED
data/lib/capcode/render/sass.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'sass'
|
3
|
-
rescue LoadError => e
|
4
|
-
raise MissingLibrary, "Sass could not be loaded (is it installed?): #{e.message}"
|
5
|
-
end
|
6
|
-
|
7
|
-
module Capcode
|
8
|
-
module Helpers
|
9
|
-
# Set the path to Sass files. If this path is not set, Capcode will search in the static path.
|
10
|
-
# This method is deprecated and will be removed in version 1.0
|
11
|
-
def self.sass_path=( p )
|
12
|
-
warn "Capcode::Helpers.sass_path is deprecated and will be removed in version 1.0, please use `set :sass'"
|
13
|
-
Capcode.set :sass, p
|
14
|
-
end
|
15
|
-
|
16
|
-
def render_sass( f, _ ) #:nodoc:
|
17
|
-
if @sass_path.nil?
|
18
|
-
@sass_path = Capcode.get( :sass ) || Capcode.static()
|
19
|
-
end
|
20
|
-
|
21
|
-
f = f.to_s
|
22
|
-
if f.include? '..'
|
23
|
-
return [403, {}, '403 - Invalid path']
|
24
|
-
end
|
25
|
-
|
26
|
-
if /Windows/.match( ENV['OS'] )
|
27
|
-
unless( /.:\\/.match( @sass_path[0] ) )
|
28
|
-
@sass_path = File.expand_path( File.join(".", @sass_path) )
|
29
|
-
end
|
30
|
-
else
|
31
|
-
unless( @sass_path[0].chr == "/" )
|
32
|
-
@sass_path = File.expand_path( File.join(".", @sass_path) )
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Get File
|
37
|
-
f = f + ".sass" if File.extname( f ) != ".sass"
|
38
|
-
file = File.join( @sass_path, f )
|
39
|
-
|
40
|
-
# Render
|
41
|
-
if( File.exist?( file ) )
|
42
|
-
Sass::Engine.new( open( file ).read ).to_css
|
43
|
-
else
|
44
|
-
raise Capcode::RenderError, "Error rendering `sass', #{file} does not exist !"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Capcode
|
2
|
-
module Helpers
|
3
|
-
def render_static( f, opts = { :exact_path => true } ) #:nodoc:
|
4
|
-
if Capcode.static.nil? or f.include? '..'
|
5
|
-
return [403, {}, '403 - Invalid path']
|
6
|
-
end
|
7
|
-
if !opts.keys.include?(:exact_path) or opts[:exact_path] == true
|
8
|
-
redirect File.join( static[:uri], f )
|
9
|
-
else
|
10
|
-
File.read( File.join( static[:path], f ) ).to_s
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# From rack_dav
|
2
|
-
require 'builder'
|
3
|
-
require 'time'
|
4
|
-
require 'uri'
|
5
|
-
require 'rexml/document'
|
6
|
-
require 'webrick/httputils'
|
7
|
-
|
8
|
-
begin
|
9
|
-
require 'rack_dav/builder_namespace'
|
10
|
-
require 'rack_dav/http_status'
|
11
|
-
require 'rack_dav/resource'
|
12
|
-
require 'rack_dav/file_resource'
|
13
|
-
require 'rack_dav/handler'
|
14
|
-
require 'rack_dav/controller'
|
15
|
-
rescue LoadError => e
|
16
|
-
raise MissingLibrary, "Rack_Dav could not be loaded (is it installed?): #{e.message}"
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
module Capcode
|
21
|
-
module Helpers
|
22
|
-
|
23
|
-
def render_webdav( f, opts )
|
24
|
-
options = {
|
25
|
-
:resource_class => RackDAV::FileResource,
|
26
|
-
:root => f
|
27
|
-
}.merge(opts)
|
28
|
-
|
29
|
-
request = Rack::Request.new(env)
|
30
|
-
response = Rack::Response.new
|
31
|
-
|
32
|
-
begin
|
33
|
-
controller = RackDAV::Controller.new(request, response, options.dup)
|
34
|
-
controller.send(request.request_method.downcase)
|
35
|
-
rescue RackDAV::HTTPStatus::Status => status
|
36
|
-
response.status = status.code
|
37
|
-
end
|
38
|
-
|
39
|
-
# Strings in Ruby 1.9 are no longer enumerable. Rack still expects the response.body to be
|
40
|
-
# enumerable, however.
|
41
|
-
response.body = [response.body] if not response.body.respond_to? :each
|
42
|
-
|
43
|
-
response.status = response.status ? response.status.to_i : 200
|
44
|
-
response.finish
|
45
|
-
|
46
|
-
[response.status, response.header, response.body]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/capcode/render/xml.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
class XML #:nodoc: all
|
2
|
-
class TagError < ArgumentError
|
3
|
-
end
|
4
|
-
|
5
|
-
class DSL
|
6
|
-
def initialize( helper, &block )
|
7
|
-
@__x_d_level = 0
|
8
|
-
@__x_d_helper = helper
|
9
|
-
@__x_d_helper.instance_variables.each do |ivar|
|
10
|
-
self.instance_variable_set(ivar, @__x_d_helper.instance_variable_get(ivar))
|
11
|
-
end
|
12
|
-
@__x_d_builder = ""
|
13
|
-
instance_eval(&block) if block
|
14
|
-
end
|
15
|
-
|
16
|
-
def __
|
17
|
-
" "*@__x_d_level
|
18
|
-
end
|
19
|
-
|
20
|
-
def _(x)
|
21
|
-
@__x_d_builder << __ << x << "\n"
|
22
|
-
end
|
23
|
-
|
24
|
-
def tag!(sym, *args, &block)
|
25
|
-
tag = {
|
26
|
-
:bra => "<",
|
27
|
-
:ket => " />",
|
28
|
-
:name => sym.id2name,
|
29
|
-
:close => block_given?(),
|
30
|
-
:attrs => "",
|
31
|
-
:value => ""
|
32
|
-
}
|
33
|
-
|
34
|
-
args.each do |a|
|
35
|
-
if a.class == Hash
|
36
|
-
a.each do |k, v|
|
37
|
-
tag[:attrs] << " #{k.to_s}='#{v}'"
|
38
|
-
end
|
39
|
-
elsif a.class == String
|
40
|
-
tag[:close] = true
|
41
|
-
tag[:value] << a << "\n"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
if tag[:name].match( /\?$/ )
|
46
|
-
tag[:name].gsub!( /\?$/, "" )
|
47
|
-
tag[:bra] = "<?"
|
48
|
-
tag[:ket] = "?>"
|
49
|
-
|
50
|
-
if tag[:close] == true
|
51
|
-
raise XML::TagError, "Malformated traitment tag!"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
@__x_d_builder << __ << tag[:bra] << "#{tag[:name]}#{tag[:attrs]}"
|
56
|
-
if tag[:close]
|
57
|
-
@__x_d_builder << ">\n"
|
58
|
-
else
|
59
|
-
@__x_d_builder << tag[:ket] << "\n"
|
60
|
-
end
|
61
|
-
|
62
|
-
@__x_d_level += 2
|
63
|
-
|
64
|
-
@__x_d_builder << __ << tag[:value] if tag[:value].size > 0
|
65
|
-
instance_eval(&block) if block
|
66
|
-
|
67
|
-
@__x_d_level -= 2
|
68
|
-
|
69
|
-
if tag[:close]
|
70
|
-
@__x_d_builder << __ << "</#{tag[:name]}>\n"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def cdata( x = "", &block )
|
75
|
-
@__x_d_builder << __ << "<![CDATA["
|
76
|
-
if x.match( /\n/ ) or block
|
77
|
-
@__x_d_level += 2
|
78
|
-
@__x_d_builder << "\n" << __ << x << "\n" if x.size > 0
|
79
|
-
instance_eval(&block) if block
|
80
|
-
@__x_d_level -= 2
|
81
|
-
@__x_d_builder << __
|
82
|
-
else
|
83
|
-
@__x_d_builder << x if x.size > 0
|
84
|
-
end
|
85
|
-
@__x_d_builder << "]]>\n"
|
86
|
-
end
|
87
|
-
|
88
|
-
def to_s
|
89
|
-
@__x_d_builder
|
90
|
-
end
|
91
|
-
|
92
|
-
def method_missing(sym, *args, &block)
|
93
|
-
if @__x_d_helper.respond_to?(sym, true)
|
94
|
-
@__x_d_helper.send(sym, *args, &block)
|
95
|
-
elsif instance_variables.include?(ivar = "@__x_d_#{sym}")
|
96
|
-
instance_variable_get(ivar)
|
97
|
-
elsif !@__x_d_helper.nil? && @__x_d_helper.instance_variables.include?(ivar)
|
98
|
-
@__x_d_helper.instance_variable_get(ivar)
|
99
|
-
else
|
100
|
-
tag!(sym, *args, &block)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
module Capcode
|
107
|
-
class XML::DSL #:nodoc:
|
108
|
-
include Views
|
109
|
-
end
|
110
|
-
|
111
|
-
module Helpers
|
112
|
-
def render_xml( f, _ ) #:nodoc:
|
113
|
-
r = XML::DSL.new( self ) do
|
114
|
-
self.send(f.to_s)
|
115
|
-
end
|
116
|
-
r.to_s
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|