capcode-render-xml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +17 -0
- data/VERSION +1 -0
- data/capcode-render-xml.gemspec +44 -0
- data/examples/render-xml.rb +25 -0
- data/examples/rss.rb +48 -0
- data/lib/capcode/render/xml.rb +119 -0
- metadata +62 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 glejeune
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "capcode-render-xml"
|
8
|
+
gem.summary = %Q{Capcode plugin to render XML}
|
9
|
+
gem.description = gem.summary
|
10
|
+
gem.email = "gregoire.lejeune@free.fr"
|
11
|
+
gem.homepage = "http://github.com/glejeune/Capcode.more/tree/master/%s" % gem.name
|
12
|
+
gem.authors = ["Gregoire Lejeune"]
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
17
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{capcode-render-xml}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Gregoire Lejeune"]
|
12
|
+
s.date = %q{2010-01-07}
|
13
|
+
s.description = %q{Capcode plugin to render XML}
|
14
|
+
s.email = %q{gregoire.lejeune@free.fr}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"capcode-render-xml.gemspec",
|
24
|
+
"examples/render-xml.rb",
|
25
|
+
"examples/rss.rb",
|
26
|
+
"lib/capcode/render/xml.rb"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-render-xml}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.5}
|
32
|
+
s.summary = %q{Capcode plugin to render XML}
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
36
|
+
s.specification_version = 3
|
37
|
+
|
38
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
39
|
+
else
|
40
|
+
end
|
41
|
+
else
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'capcode'
|
3
|
+
$:.unshift( "../lib" )
|
4
|
+
require 'capcode/render/xml'
|
5
|
+
|
6
|
+
module Capcode
|
7
|
+
class Index < Route '/'
|
8
|
+
def get
|
9
|
+
render :xml => :index
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Capcode::Views
|
15
|
+
def index
|
16
|
+
xml? :version => '1.0'
|
17
|
+
html do
|
18
|
+
body do
|
19
|
+
h1 "Hello XML !"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Capcode.run( )
|
data/examples/rss.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'capcode'
|
3
|
+
$:.unshift( "../lib" )
|
4
|
+
require 'capcode/render/xml'
|
5
|
+
|
6
|
+
## !! THIS IS JUSTE FOR THIS EXAMPLE !!
|
7
|
+
class Hash
|
8
|
+
def method_missing( id, *a )
|
9
|
+
self[id.id2name.to_sym]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Capcode
|
14
|
+
class RSS < Route "/rss"
|
15
|
+
def get
|
16
|
+
@posts = [
|
17
|
+
{ :title => "Welcome", :body => "This is a RSS example for Capcode!", :iid => 1, :created_at => Time.now() },
|
18
|
+
{ :title => "Just For Fun", :body => "See more examples on the Capcode Website...", :iid => 2, :created_at => Time.now() },
|
19
|
+
]
|
20
|
+
render :xml => :rss_view
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Capcode::Views
|
26
|
+
def rss_view
|
27
|
+
xml? :version => '1.0'
|
28
|
+
rss :version => "2.0" do
|
29
|
+
channel do
|
30
|
+
title "Capcode News"
|
31
|
+
description "Capcode Framework."
|
32
|
+
link "http://example.com/"
|
33
|
+
|
34
|
+
@posts.each do |post|
|
35
|
+
item do
|
36
|
+
title post.title
|
37
|
+
link "http://example.com/posts/#{post.iid}"
|
38
|
+
description post.body
|
39
|
+
pubDate Time.parse(post.created_at.to_s).rfc822()
|
40
|
+
guid "http://example.com/posts/#{post.iid}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Capcode.run()
|
@@ -0,0 +1,119 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capcode-render-xml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregoire Lejeune
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-07 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Capcode plugin to render XML
|
17
|
+
email: gregoire.lejeune@free.fr
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- LICENSE
|
26
|
+
- README.rdoc
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- capcode-render-xml.gemspec
|
30
|
+
- examples/render-xml.rb
|
31
|
+
- examples/rss.rb
|
32
|
+
- lib/capcode/render/xml.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-render-xml
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Capcode plugin to render XML
|
61
|
+
test_files: []
|
62
|
+
|