reparcs 0.1.0 → 0.1.5
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/History.txt +17 -0
- data/Rakefile +7 -17
- data/lib/reparcs.rb +4 -1
- data/lib/reparcs/base.rb +26 -28
- data/lib/reparcs/elements/hypertext_elements.rb +0 -2
- data/lib/reparcs/elements/structure_elements.rb +1 -1
- data/lib/reparcs/shortcuts.rb +0 -3
- data/lib/reparcs/utilities.rb +16 -1
- data/test/test_shortcuts.rb +40 -1
- data/test/test_validmarkup.rb +2 -1
- metadata +4 -5
- data/CHANGES +0 -10
- data/www/create_www.rb +0 -85
data/History.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
== 0.1.5 08/09/2008:
|
2
|
+
* 1 Fixed
|
3
|
+
* A bug where if you called to_s on all elements more than once, the entire html of the element would be appended to its children.
|
4
|
+
* 2 Added
|
5
|
+
* XML entities conversion for StringElements.
|
6
|
+
|
7
|
+
== 0.1.0 06/09/2008:
|
8
|
+
* 1 Updated
|
9
|
+
* All element classes with there correct 'allowed attributes and child elements'.
|
10
|
+
|
11
|
+
== 0.0.4 04/09/2008:
|
12
|
+
* 1 Changed
|
13
|
+
* Removed Heading1, 2 and 3 classes and replaced with Heading with a size parameter for its constructor.
|
14
|
+
|
15
|
+
== 0.0.1 02/09/2008:
|
16
|
+
* 1 Fixed
|
17
|
+
* 'attribute' and 'child' not allowed for element(all types) error
|
data/Rakefile
CHANGED
@@ -19,7 +19,7 @@ UNIX_NAME = "reparcs"
|
|
19
19
|
RUBYFORGE_USER = ENV["RUBYFORGE_USER"] || "kanodii"
|
20
20
|
RDOC_HTML_FILES = "doc"
|
21
21
|
|
22
|
-
WEBSITE_DIR = "
|
22
|
+
WEBSITE_DIR = "doc"
|
23
23
|
RDOC_HTML_DIR = "doc"
|
24
24
|
|
25
25
|
EXT_DIR = "ext"
|
@@ -37,10 +37,10 @@ CLOBBER.include("#{EXT_DIR}/**/*.{so,dll,o}", "#{EXT_DIR}/**/Makefile")
|
|
37
37
|
CLOBBER.include(".config")
|
38
38
|
|
39
39
|
GENERAL_RDOC_OPTS = {
|
40
|
-
"--title" => "#{PROJECT}
|
40
|
+
"--title" => "#{PROJECT} Library documentation",
|
41
41
|
"--main" => "README"
|
42
42
|
}
|
43
|
-
RDOC_FILES = FileList["README", "
|
43
|
+
RDOC_FILES = FileList["README", "History.txt", "LICENSE"]
|
44
44
|
LIB_FILES = FileList["lib/**/*.rb"]
|
45
45
|
TEST_FILES = FileList["test/test_*.rb"]
|
46
46
|
DIST_FILES = FileList["**/*.rb", "**/*.rdoc"]
|
@@ -149,17 +149,15 @@ task "publish-packages" => ["package", "rubyforge-login"] do
|
|
149
149
|
# This task makes some assumptions:
|
150
150
|
# * You have already created a package on the "Files" tab on the
|
151
151
|
# RubyForge
|
152
|
-
project page. See pkg_name variable below.
|
152
|
+
# project page. See pkg_name variable below.
|
153
153
|
# * You made entries under package_ids and group_ids for this
|
154
154
|
# project in rubyforge's config.yml. If not, eventually read
|
155
155
|
# "rubyforge --help" and then run "rubyforge setup".
|
156
|
-
pkg_name =
|
157
|
-
cmd = "rubyforge add_release #{UNIX_NAME} #{pkg_name} " +
|
156
|
+
pkg_name = UNIX_NAME
|
157
|
+
cmd = "rubyforge add_release -a 'History.txt' #{UNIX_NAME} #{pkg_name} " +
|
158
158
|
"#{PROJECT_VERSION} #{UNIX_NAME}-#{PROJECT_VERSION}"
|
159
159
|
cd "pkg" do
|
160
160
|
sh(cmd + ".gem", :verbose => true)
|
161
|
-
sh(cmd + ".tgz", :verbose => true)
|
162
|
-
sh(cmd + ".zip", :verbose => true)
|
163
161
|
end
|
164
162
|
end
|
165
163
|
|
@@ -167,7 +165,7 @@ end
|
|
167
165
|
# files for a new release.
|
168
166
|
desc "Run tests, generate RDoc and create packages."
|
169
167
|
task "prepare-release" => ["clobber"] do
|
170
|
-
puts "Preparing release of #{PROJECT} version #{
|
168
|
+
puts "Preparing release of #{PROJECT} version #{PROJECT_VERSION}"
|
171
169
|
Rake::Task["test"].invoke
|
172
170
|
Rake::Task["rdoc"].invoke
|
173
171
|
Rake::Task["package"].invoke
|
@@ -177,8 +175,6 @@ end
|
|
177
175
|
# builds a release and then publishes it to RubyForge.
|
178
176
|
desc "Publish new release of #{PROJECT}"
|
179
177
|
task "publish" => ["prepare-release"] do
|
180
|
-
puts "Creating www..."
|
181
|
-
Rake::Task["generate-www"].invoke
|
182
178
|
puts "Uploading documentation…"
|
183
179
|
Rake::Task["publish-website"].invoke
|
184
180
|
puts "Checking for rubyforge command…"
|
@@ -191,10 +187,4 @@ task "publish" => ["prepare-release"] do
|
|
191
187
|
puts "Either install rubyforge with 'gem install rubyforge'"
|
192
188
|
puts "and retry or upload the package files manually!"
|
193
189
|
end
|
194
|
-
end
|
195
|
-
|
196
|
-
#Generate rubyforge website HTML
|
197
|
-
desc "Generate the Rubyforge website for #{PROJECT}"
|
198
|
-
task "generate-www" do
|
199
|
-
sh("ruby www/create_www.rb")
|
200
190
|
end
|
data/lib/reparcs.rb
CHANGED
@@ -21,6 +21,9 @@ require 'reparcs/projects'
|
|
21
21
|
require 'reparcs/utilities'
|
22
22
|
require 'reparcs/shortcuts'
|
23
23
|
|
24
|
+
include XMLEntities
|
25
|
+
include Utilities
|
26
|
+
|
24
27
|
include Projects
|
25
28
|
|
26
29
|
include BaseElements
|
@@ -42,5 +45,5 @@ include StylesheetElements
|
|
42
45
|
include Shortcuts
|
43
46
|
|
44
47
|
module Reparcs
|
45
|
-
VERSION = "0.1.
|
48
|
+
VERSION = "0.1.5"
|
46
49
|
end
|
data/lib/reparcs/base.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'reparcs/utilities'
|
2
|
+
|
3
|
+
include Utilities
|
4
|
+
|
1
5
|
#Reparcs base elements
|
2
6
|
module Base
|
3
7
|
|
@@ -12,21 +16,21 @@ module Base
|
|
12
16
|
@attributes = {}
|
13
17
|
@allowed_attributes = allowed_attrs
|
14
18
|
attrs.each do |key, val|
|
15
|
-
set_attribute(key, val)
|
19
|
+
self.set_attribute(key, val)
|
16
20
|
end
|
17
21
|
@start_element = ""
|
18
22
|
@end_element = ""
|
19
23
|
end
|
20
|
-
#Returns the
|
21
|
-
def
|
22
|
-
html = start_element
|
23
|
-
@attributes.each do |key,
|
24
|
-
html << " #{key}=\"#{
|
24
|
+
#Returns the html representation of the Element
|
25
|
+
def to_html
|
26
|
+
html = "#{@start_element}"
|
27
|
+
@attributes.each do |key, attri|
|
28
|
+
html << " #{key}=\"#{attri}\""
|
25
29
|
end
|
26
|
-
if end_element != " />"
|
30
|
+
if @end_element != " />"
|
27
31
|
html << ">"
|
28
32
|
end
|
29
|
-
html << end_element
|
33
|
+
html << @end_element
|
30
34
|
return html
|
31
35
|
end
|
32
36
|
#Checks to see if a certain attribute is allowed for this element,
|
@@ -46,7 +50,7 @@ module Base
|
|
46
50
|
if is_attribute_allowed?(attr_name)
|
47
51
|
@attributes["#{attr_name}"] = value
|
48
52
|
else
|
49
|
-
raise "The '#{attr_name}' attribute is not allowed for the #{
|
53
|
+
raise "The '#{attr_name}' attribute is not allowed for the '#{@string_name}' element."
|
50
54
|
end
|
51
55
|
end
|
52
56
|
#Checks to see if an attribute has been set for this element
|
@@ -85,7 +89,7 @@ module Base
|
|
85
89
|
def is_child_allowed?(child_type)
|
86
90
|
allowed = false
|
87
91
|
@allowed_child_elements.each do |e|
|
88
|
-
if e == child_type
|
92
|
+
if e == child_type.to_s
|
89
93
|
allowed = true
|
90
94
|
break
|
91
95
|
end
|
@@ -98,28 +102,22 @@ module Base
|
|
98
102
|
item = StringElement.new(item)
|
99
103
|
end
|
100
104
|
if is_child_allowed?(item.string_name)
|
101
|
-
if item.class == String
|
102
|
-
@children << StringElement.new(item)
|
103
|
-
else
|
104
105
|
@children << item
|
105
|
-
end
|
106
106
|
else
|
107
|
-
raise "#{@string_name} element's can not contain a #{item.string_name} child
|
107
|
+
raise "#'{@string_name}' element's can not contain a '#{item.string_name}' child elements."
|
108
108
|
end
|
109
109
|
end
|
110
110
|
#Returns the string representation of this element
|
111
|
-
def
|
112
|
-
html = start_element
|
113
|
-
@attributes.each do |key,
|
114
|
-
html << " #{key}=\"#{
|
115
|
-
end
|
116
|
-
if end_element != " />"
|
117
|
-
html << ">"
|
111
|
+
def to_html
|
112
|
+
html = "#{@start_element}"
|
113
|
+
@attributes.each do |key, attri|
|
114
|
+
html << " #{key}=\"#{attri}\""
|
118
115
|
end
|
116
|
+
html << ">"
|
119
117
|
@children.each do |child|
|
120
|
-
html << child.
|
118
|
+
html << child.to_html
|
121
119
|
end
|
122
|
-
html << end_element
|
120
|
+
html << @end_element
|
123
121
|
return html
|
124
122
|
end
|
125
123
|
#Does this element have any child elements?
|
@@ -138,19 +136,19 @@ module Base
|
|
138
136
|
class StringElement
|
139
137
|
#Create a new StringElement
|
140
138
|
def initialize(stri)
|
141
|
-
@stri = stri
|
139
|
+
@stri = put_xml_entities(stri)
|
142
140
|
@string_name = "string"
|
143
141
|
end
|
144
142
|
#Returns the string representation of this element
|
145
|
-
def
|
143
|
+
def to_html
|
146
144
|
return @stri
|
147
145
|
end
|
148
146
|
#Append a string to the string
|
149
147
|
def append(text)
|
150
148
|
if text.class == String
|
151
|
-
@stri << text
|
149
|
+
@stri << put_xml_entities(text)
|
152
150
|
else
|
153
|
-
raise "#{self.
|
151
|
+
raise "#{self.to_html} is a String, you can only append String's to it!"
|
154
152
|
end
|
155
153
|
end
|
156
154
|
attr_reader :string_name
|
data/lib/reparcs/shortcuts.rb
CHANGED
data/lib/reparcs/utilities.rb
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
#Useful utilities
|
2
2
|
module Utilities
|
3
|
-
|
3
|
+
#Replaces invalid XML characters (£, <, >, etc with there xml entity)
|
4
|
+
def put_xml_entities(text)
|
5
|
+
new_t = text
|
6
|
+
ENTITIES.each do |key, val|
|
7
|
+
new_t = new_t.gsub(key, val)
|
8
|
+
end
|
9
|
+
return new_t
|
10
|
+
end
|
11
|
+
#Replaces XML entities with the equivalent character.
|
12
|
+
def remove_xml_entities(text)
|
13
|
+
new_t = text
|
14
|
+
ENTITIES.each do |key, val|
|
15
|
+
new_t = new_t.gsub(val, key)
|
16
|
+
end
|
17
|
+
return new_t
|
18
|
+
end
|
4
19
|
end
|
data/test/test_shortcuts.rb
CHANGED
@@ -5,6 +5,8 @@ require 'test/unit'
|
|
5
5
|
#Reparcs shortcut tests
|
6
6
|
class ShortcutsTest < Test::Unit::TestCase
|
7
7
|
|
8
|
+
include Base
|
9
|
+
include Utilities
|
8
10
|
include Shortcuts
|
9
11
|
include TableElements
|
10
12
|
|
@@ -42,7 +44,44 @@ class ShortcutsTest < Test::Unit::TestCase
|
|
42
44
|
["SnipIt!", "http://snipit.kanodi.com"]
|
43
45
|
]
|
44
46
|
tbl = shortcut_table(headers, data)
|
45
|
-
html = tbl.
|
47
|
+
html = tbl.to_html.gsub(/(\n|\t| )/, "")
|
48
|
+
assert(html == desired_html)
|
49
|
+
end
|
50
|
+
|
51
|
+
#Tests the shortcut_anchor method
|
52
|
+
def test_shortcut_anchor
|
53
|
+
desired_html = %{<a href="http://google.co.uk" class="links">Google</a>}
|
54
|
+
anchor = Anchor.new({:href => 'http://google.co.uk', :class => 'links'})
|
55
|
+
anchor.append("Google")
|
56
|
+
assert(anchor.to_html == desired_html)
|
57
|
+
end
|
58
|
+
|
59
|
+
#Tests the shortcut_unordered_list method
|
60
|
+
def test_shortcut_unorderedlist
|
61
|
+
names = ["Lee", "Caine", "kanodi", "reparcs"]
|
62
|
+
desired_html = %{<ul class="names">}
|
63
|
+
names.each { |n| desired_html << %{<li>#{n}</li>}}
|
64
|
+
desired_html << "</ul>"
|
65
|
+
list = shortcut_unordered_list(names)
|
66
|
+
list.set_attribute("class", "names")
|
67
|
+
assert(list.to_html == desired_html)
|
68
|
+
end
|
69
|
+
|
70
|
+
#Tests the shortcut_unordered_list method by passing anchors
|
71
|
+
def test_shortcut_unordered_list_with_anchors
|
72
|
+
names = [
|
73
|
+
shortcut_anchor('http://google.co.uk', 'Google'),
|
74
|
+
shortcut_anchor('http://kanodi.com', 'Kanodi > blog')
|
75
|
+
]
|
76
|
+
desired_html = %{<ul class="names">}
|
77
|
+
names.each do |n|
|
78
|
+
desired_html << "<li>#{n.to_html}</li>"
|
79
|
+
end
|
80
|
+
desired_html << "</ul>"
|
81
|
+
desired_html = desired_html.gsub(/(\t|\n)/, "")
|
82
|
+
list = shortcut_unordered_list(names)
|
83
|
+
list.set_attribute("class", "names")
|
84
|
+
html = list.to_html.gsub(/(\t|\n)/, "")
|
46
85
|
assert(html == desired_html)
|
47
86
|
end
|
48
87
|
|
data/test/test_validmarkup.rb
CHANGED
@@ -7,6 +7,7 @@ require 'test/unit'
|
|
7
7
|
class ValidXHTMLStrictTest < Test::Unit::TestCase
|
8
8
|
|
9
9
|
include Projects
|
10
|
+
include Utilities
|
10
11
|
include HTTPHelpers
|
11
12
|
|
12
13
|
#Tests the blank html document created by the Page class for validation
|
@@ -16,7 +17,7 @@ class ValidXHTMLStrictTest < Test::Unit::TestCase
|
|
16
17
|
title.append("Standard page test")
|
17
18
|
page.head.append(title)
|
18
19
|
f = File.new('temp/valid_standard_test.html', 'w')
|
19
|
-
f.puts page.
|
20
|
+
f.puts page.to_html
|
20
21
|
f.close()
|
21
22
|
assert(w3c_validate?('temp/valid_standard_test.html'))
|
22
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reparcs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Caine
|
@@ -21,7 +21,7 @@ extensions: []
|
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README
|
24
|
-
-
|
24
|
+
- History.txt
|
25
25
|
- LICENSE
|
26
26
|
files:
|
27
27
|
- lib/reparcs/base.rb
|
@@ -48,17 +48,16 @@ files:
|
|
48
48
|
- test/http_helpers.rb
|
49
49
|
- test/test_shortcuts.rb
|
50
50
|
- test/test_validmarkup.rb
|
51
|
-
- www/create_www.rb
|
52
51
|
- Rakefile
|
53
52
|
- README
|
54
|
-
-
|
53
|
+
- History.txt
|
55
54
|
- LICENSE
|
56
55
|
has_rdoc: true
|
57
56
|
homepage: http://reparcs.rubyforge.org/
|
58
57
|
post_install_message:
|
59
58
|
rdoc_options:
|
60
59
|
- --title
|
61
|
-
- Reparcs
|
60
|
+
- Reparcs Library documentation
|
62
61
|
- --main
|
63
62
|
- README
|
64
63
|
require_paths:
|
data/CHANGES
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
0.1.0 - 06/09/2008:
|
2
|
-
Updated - All element classes with there correct 'allowed attributes and
|
3
|
-
child elements'.
|
4
|
-
|
5
|
-
0.0.4 - 04/09/2008:
|
6
|
-
Changed - Removed Heading1, 2 and 3 classes and replaced with Heading with
|
7
|
-
a size parameter for its constructor.
|
8
|
-
|
9
|
-
0.0.1 - 02/09/2008:
|
10
|
-
Fixed - 'attribute' and 'child' not allowed for element(all types) error
|
data/www/create_www.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
#Creates the reparcs rubyforge webpage, using reparcs....
|
2
|
-
#
|
3
|
-
# by Lee Caine | kanodii@gmail.com | http://kanodi.com
|
4
|
-
#
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
7
|
-
require 'reparcs.rb'
|
8
|
-
require 'test/unit'
|
9
|
-
|
10
|
-
page = Page.new
|
11
|
-
page.head.append(shortcut_title("reparcs - XHTML generation library for Ruby"))
|
12
|
-
page.head.append(shortcut_style(%{
|
13
|
-
h1 {
|
14
|
-
font-size: 20px;
|
15
|
-
color: #D15600;
|
16
|
-
}
|
17
|
-
|
18
|
-
h2 {
|
19
|
-
font-size: 16px;
|
20
|
-
color: #3F4C6B;
|
21
|
-
}
|
22
|
-
|
23
|
-
#main {
|
24
|
-
width: 300px;
|
25
|
-
float: left;
|
26
|
-
}
|
27
|
-
|
28
|
-
#links {
|
29
|
-
width: 200px;
|
30
|
-
border: 5px solid #666666;
|
31
|
-
background-color: #FFFF88;
|
32
|
-
float: right;
|
33
|
-
}
|
34
|
-
|
35
|
-
#links ul {
|
36
|
-
list-style-type: none;
|
37
|
-
width: 100%;
|
38
|
-
margin-left: 0px;
|
39
|
-
padding-left: 0px;
|
40
|
-
}
|
41
|
-
|
42
|
-
#links ul li {
|
43
|
-
display: block;
|
44
|
-
color: #666666;
|
45
|
-
text-align: center;
|
46
|
-
}
|
47
|
-
|
48
|
-
#links ul li:hover {
|
49
|
-
background-color: #666666;
|
50
|
-
color: white;
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
#footer {
|
55
|
-
clear: both;
|
56
|
-
}
|
57
|
-
}))
|
58
|
-
page.body.append(shortcut_header(1, "Reparcs V#{Reparcs::VERSION}"))
|
59
|
-
main = Division.new({:id => 'main'})
|
60
|
-
pre = Preformat.new
|
61
|
-
readme_content = File.new('README', 'r').read
|
62
|
-
readme = readme_content.gsub(/^(.):/, "<h2>#{$0}</h2>")
|
63
|
-
pre.append(readme)
|
64
|
-
main.append(pre)
|
65
|
-
page.body.append(main)
|
66
|
-
|
67
|
-
links = Division.new({:id => 'links'})
|
68
|
-
as = [
|
69
|
-
shortcut_anchor('http://rubyforge.org/projects/reparcs/', 'Rubyforge project page'),
|
70
|
-
shortcut_anchor("http://rubyforge.org/projects/reparcs/files/reparcs-#{VERSION}.gem", 'Download latest GEM'),
|
71
|
-
shortcut_anchor('http://reparcs.rubyforge.org/changes.html', 'Changes'),
|
72
|
-
shortcut_anchor('http://kanodi.com', 'Developers blog')
|
73
|
-
]
|
74
|
-
links_list = shortcut_unordered_list(as)
|
75
|
-
links.append(links_list)
|
76
|
-
page.body.append(links)
|
77
|
-
|
78
|
-
footer = Division.new({:id => 'footer'})
|
79
|
-
footer.append(HorizontalRule.new)
|
80
|
-
footer.append(shortcut_anchor('http://validator.w3.org/check?uri=referer', 'Valid XHTML'))
|
81
|
-
page.body.append(footer)
|
82
|
-
|
83
|
-
save = File.new('www/index.html', 'w')
|
84
|
-
save.write(page.to_s)
|
85
|
-
save.close()
|