reparcs 0.2.1 → 0.2.8
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 +25 -3
- data/README +80 -1
- data/lib/reparcs.rb +1 -1
- data/lib/reparcs/base.rb +5 -1
- data/lib/reparcs/elements/form_elements.rb +1 -1
- data/lib/reparcs/elements/text_elements.rb +1 -1
- data/lib/reparcs/projects.rb +17 -0
- data/lib/reparcs/shortcuts.rb +1 -1
- data/lib/reparcs/xml_entities.rb +6 -1
- data/test/test_shortcuts.rb +7 -1
- data/test/test_validmarkup.rb +76 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
== 0.2.8 09/09/2008:
|
2
|
+
* 1 Added
|
3
|
+
* PageWithScript and WebsiteWithScript classes to projects.rb, which are simply there superclasses
|
4
|
+
with the scriptaculous scripts included for a quick shortcut.
|
5
|
+
* 2 Updated
|
6
|
+
* the list of XML entities.
|
7
|
+
* 3 Added
|
8
|
+
* Several more XHTML validation unit tests(which pass(for now :)))
|
9
|
+
* 4 Fixed
|
10
|
+
* The Page.include_scriptaculous method was not adding the type attribute
|
11
|
+
to the Script elements, resulting in invalid XHTML
|
12
|
+
* 5 Fixed
|
13
|
+
* error, when an exception is raised whilst attempting to append an element to another and it is not
|
14
|
+
allowed, the exception would read #'{@string_name} rather than the actual string name of the element.
|
15
|
+
* 6 Fixed
|
16
|
+
* Division 'div' elements were not allowed to have table 'table' elements as children.
|
17
|
+
* 7 Fixed
|
18
|
+
* Option elements ere not allowed to have the 'value' attribute.
|
19
|
+
|
1
20
|
== 0.2.1 09/09/2008:
|
2
21
|
* 1 Fixed
|
3
22
|
* error copying javascript files to Website's publish directory.
|
@@ -6,13 +25,16 @@
|
|
6
25
|
* 1 Added
|
7
26
|
* Included the prototype & scriptaculous javascript files to the project
|
8
27
|
* 2 Added
|
9
|
-
* A Website class to projects.rb, where you can add css, javascript, and images files to it, the class
|
28
|
+
* A Website class to projects.rb, where you can add css, javascript, and images files to it, the class
|
29
|
+
has a publish method which creates the whole website structure.
|
10
30
|
* 3 Added
|
11
|
-
* A include_scriptaculous method to the Page class, whcih includes a script element for each javascript
|
31
|
+
* A include_scriptaculous method to the Page class, whcih includes a script element for each javascript
|
32
|
+
file in the scriptaculous library.
|
12
33
|
|
13
34
|
== 0.1.5 08/09/2008:
|
14
35
|
* 1 Fixed
|
15
|
-
* A bug where if you called to_s on all elements more than once, the entire html of the element would
|
36
|
+
* A bug where if you called to_s on all elements more than once, the entire html of the element would
|
37
|
+
be appended to its children.
|
16
38
|
* 2 Added
|
17
39
|
* XML entities conversion for StringElements.
|
18
40
|
|
data/README
CHANGED
@@ -21,5 +21,84 @@ Homepage:
|
|
21
21
|
http://reparcs.rubyforge.org
|
22
22
|
|
23
23
|
Rubyforge project page:
|
24
|
-
http://rubyforge.org/projects/
|
24
|
+
http://rubyforge.org/projects/reparcs
|
25
|
+
|
26
|
+
Example:
|
27
|
+
|
28
|
+
#Include the library
|
29
|
+
require 'rubygems'
|
30
|
+
require 'reparcs'
|
31
|
+
|
32
|
+
#Create a new website
|
33
|
+
my_project = Website.new
|
34
|
+
#Create and add a page
|
35
|
+
index_page = Page.new
|
36
|
+
my_project.append("index", index_page)
|
37
|
+
|
38
|
+
#Now lets design the page...
|
39
|
+
#Set the title
|
40
|
+
index_page.head.append(shortcut_title("Home"))
|
41
|
+
#Create a layer 'div'
|
42
|
+
main_layer = Division.new
|
43
|
+
#Add a header
|
44
|
+
main_layer.append(shortcut_header(1, "Welcome.."))
|
45
|
+
#Add a paragraph with some text..
|
46
|
+
para = Paragraph.new
|
47
|
+
para.append(%{
|
48
|
+
"Welcome to my site, it contains a whole bunch of crap...."
|
49
|
+
})
|
50
|
+
#Add the paragraph to the layer
|
51
|
+
main_layer.append(para)
|
52
|
+
#Lets add some links
|
53
|
+
links = [
|
54
|
+
shortcut_anchor("http://google.co.uk", "Google"),
|
55
|
+
shortcut_anchor("http://rubyforge.org", "Rubyforge"),
|
56
|
+
shortcut_anchor("http://kanodi.com", "Kanodi"),
|
57
|
+
shortcut_anchor("http://reparcs.rubyforge.org", "Reparcs")
|
58
|
+
]
|
59
|
+
ul = shortcut_unordered_list(links)
|
60
|
+
main_layer.append(ul)
|
61
|
+
#I suppose we better add the layer to the page's body..
|
62
|
+
index_page.body.append(main_layer)
|
63
|
+
#It is all going to look a little boring lets style it..
|
64
|
+
#before we add some css, we better add some id attributes to
|
65
|
+
#our elements
|
66
|
+
main_layer.set_attribute("id", "main")
|
67
|
+
ul.set_attribute("id", "links")
|
68
|
+
#Ok lets add some style
|
69
|
+
index_page.head.append(shortcut_style(%{
|
70
|
+
#main {
|
71
|
+
width: 400px;
|
72
|
+
border: 5px solid #666666
|
73
|
+
float: left;
|
74
|
+
}
|
75
|
+
|
76
|
+
#links {
|
77
|
+
list-style-type: none;
|
78
|
+
}
|
79
|
+
|
80
|
+
#links ul li {
|
81
|
+
display: block;
|
82
|
+
}
|
83
|
+
})
|
84
|
+
#Why we are at it shall we add some cool effects?...
|
85
|
+
#To add an effect to an element it must have an id attribute
|
86
|
+
#So lets add id's to out anchors..
|
87
|
+
id = 0
|
88
|
+
links.each do |l|
|
89
|
+
l.set_attribute("id", "link#{id}")
|
90
|
+
id += 1
|
91
|
+
#We may aswell add the effect whilst we are in the loop
|
92
|
+
index_page.add_effect(l, "onmouseover", "Grow")
|
93
|
+
end
|
94
|
+
#Aswell as setting the effect, we need to include the prototype &
|
95
|
+
#scriptaculous libraries..
|
96
|
+
my_project.include_scriptaculous_files
|
97
|
+
index_page.include_scriptaculous
|
98
|
+
|
99
|
+
#Now lets publish the whole lot
|
100
|
+
my_project.publish("/Users/bigk/Desktop/www")
|
101
|
+
|
102
|
+
#This would create 1 html file called "index.html" and a javascript directory containing all the
|
103
|
+
#scriptaculous library files.
|
25
104
|
|
data/lib/reparcs.rb
CHANGED
data/lib/reparcs/base.rb
CHANGED
@@ -104,7 +104,7 @@ module Base
|
|
104
104
|
if is_child_allowed?(item.string_name)
|
105
105
|
@children << item
|
106
106
|
else
|
107
|
-
raise "#
|
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
|
@@ -128,6 +128,10 @@ module Base
|
|
128
128
|
return false
|
129
129
|
end
|
130
130
|
end
|
131
|
+
#Returns this elements children
|
132
|
+
def get_children
|
133
|
+
return @children
|
134
|
+
end
|
131
135
|
attr_accessor :children
|
132
136
|
end
|
133
137
|
|
@@ -190,7 +190,7 @@ module FormElements
|
|
190
190
|
"class", "id", "title", "dir", "xml:lang",
|
191
191
|
"onclick", "ondblclick", "onkeydown", "onkeypress",
|
192
192
|
"onkeyup", "onmousedown", "onmousemove", "onmouseout",
|
193
|
-
"onmouseover", "onmouseup", "style"
|
193
|
+
"onmouseover", "onmouseup", "style", "value"
|
194
194
|
]
|
195
195
|
super("option", aattrs, [], attrs)
|
196
196
|
@start_element = "<option"
|
@@ -177,7 +177,7 @@ module TextElements
|
|
177
177
|
"fieldset", "form", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "i",
|
178
178
|
"img", "input", "ins", "kbd", "label", "map", "noscript", "object",
|
179
179
|
"ol", "p", "pre", "q", "samp", "script", "select", "small", "span",
|
180
|
-
"strong", "sub", "sup", "textarea", "tt", "ul", "var"
|
180
|
+
"strong", "sub", "sup", "table", "textarea", "tt", "ul", "var"
|
181
181
|
]
|
182
182
|
super("div", aattrs, childs, attrs)
|
183
183
|
@start_element = "<div"
|
data/lib/reparcs/projects.rb
CHANGED
@@ -48,6 +48,7 @@ module Projects
|
|
48
48
|
Dir.foreach(JAVASCRIPT_LIB_PATH) { |f|
|
49
49
|
unless f[0,1] == "."
|
50
50
|
s = Script.new({:src => "javascript/#{f}"})
|
51
|
+
s.set_attribute("type", "text/javascript")
|
51
52
|
@head.append(s)
|
52
53
|
end
|
53
54
|
}
|
@@ -72,6 +73,14 @@ module Projects
|
|
72
73
|
attr_accessor :head, :body, :xml_lang, :lang, :xmlns, :charset
|
73
74
|
end
|
74
75
|
|
76
|
+
#The PageWithScript class is simply a Page with the scriptaculous files included
|
77
|
+
class PageWithScript < Page
|
78
|
+
def initialize
|
79
|
+
super
|
80
|
+
self.include_scriptaculous
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
75
84
|
#A Website, a good starting point for larger projects, that require
|
76
85
|
#other files, etc.
|
77
86
|
class Website
|
@@ -145,4 +154,12 @@ module Projects
|
|
145
154
|
end
|
146
155
|
end
|
147
156
|
|
157
|
+
#The WebsiteWithScript class is simply a Website with the scriptaculous files included.
|
158
|
+
class WebsiteWithScript < Website
|
159
|
+
def initialize
|
160
|
+
super
|
161
|
+
self.include_scriptaculous_files
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
148
165
|
end
|
data/lib/reparcs/shortcuts.rb
CHANGED
data/lib/reparcs/xml_entities.rb
CHANGED
data/test/test_shortcuts.rb
CHANGED
@@ -81,8 +81,14 @@ class ShortcutsTest < Test::Unit::TestCase
|
|
81
81
|
desired_html = desired_html.gsub(/(\t|\n)/, "")
|
82
82
|
list = shortcut_unordered_list(names)
|
83
83
|
list.set_attribute("class", "names")
|
84
|
-
html = list.to_html.gsub(/(\t|\n)/, "")
|
84
|
+
html = list.to_html.gsub(/(\t|\n| )/, "")
|
85
85
|
assert(html == desired_html)
|
86
86
|
end
|
87
87
|
|
88
|
+
def test_shortcut_select
|
89
|
+
desired_html = %{<select><option value="red">Red</option><option value="blue">Blue</option></select>}
|
90
|
+
select = shortcut_select({:Blue => 'blue', :Red => 'red'})
|
91
|
+
assert(select.to_html == desired_html)
|
92
|
+
end
|
93
|
+
|
88
94
|
end
|
data/test/test_validmarkup.rb
CHANGED
@@ -21,4 +21,80 @@ class ValidXHTMLStrictTest < Test::Unit::TestCase
|
|
21
21
|
f.close()
|
22
22
|
assert(w3c_validate?('temp/valid_standard_test.html'))
|
23
23
|
end
|
24
|
+
|
25
|
+
#Test a basic page where xml character entities have been appended
|
26
|
+
def test_xml_entities
|
27
|
+
page = Page.new
|
28
|
+
title = Title.new
|
29
|
+
title.append("My amazing site & stuff")
|
30
|
+
page.head.append(title)
|
31
|
+
f = File.new('temp/valid_xml_entities_test.html', 'w')
|
32
|
+
f.puts page.to_html
|
33
|
+
f.close
|
34
|
+
assert(w3c_validate?('temp/valid_xml_entities_test.html'))
|
35
|
+
end
|
36
|
+
|
37
|
+
#Markup that should fail validation, if this passes I know that
|
38
|
+
#the validator method is working
|
39
|
+
def test_invalid
|
40
|
+
page = Page.new
|
41
|
+
title = Title.new
|
42
|
+
title.append("My amazing site & stuff")
|
43
|
+
page.head.append(title)
|
44
|
+
f = File.new('temp/valid_invalid_test.html', 'w')
|
45
|
+
invalid_html = page.to_html.gsub("/>", "")
|
46
|
+
f.puts invalid_html
|
47
|
+
f.close
|
48
|
+
assert(!w3c_validate?('temp/valid_invalid_test.html'))
|
49
|
+
end
|
50
|
+
|
51
|
+
#Tests the validation of a slightly more complex page
|
52
|
+
def test_more_complex_page
|
53
|
+
page = Page.new
|
54
|
+
page.include_scriptaculous
|
55
|
+
title = Title.new
|
56
|
+
title.append("My amazing site & stuff")
|
57
|
+
stylesheet = Link.new({:rel => 'stylesheet', :type => 'text/css', :media => 'screen'})
|
58
|
+
stylesheet.set_attribute("href", "http://somwhere.com/some.css")
|
59
|
+
page.head.append(stylesheet)
|
60
|
+
page.head.append(title)
|
61
|
+
main = Division.new({:id => 'main'})
|
62
|
+
page.body.append(main)
|
63
|
+
main.append(shortcut_header(1, "My names.."))
|
64
|
+
names = ["Lee", "kanodi", "reparcs"]
|
65
|
+
ul = shortcut_unordered_list(names)
|
66
|
+
id = 0
|
67
|
+
ul.get_children.each do |li|
|
68
|
+
if li.class == ListItem
|
69
|
+
li.set_attribute("id", "li#{id}")
|
70
|
+
page.add_effect(li, "onmouseover", "Grow")
|
71
|
+
id += 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
main.append(ul)
|
75
|
+
f = File.new('temp/valid_complex_test.html', 'w')
|
76
|
+
f.puts page.to_html
|
77
|
+
f.close
|
78
|
+
assert(w3c_validate?('temp/valid_complex_test.html'))
|
79
|
+
end
|
80
|
+
|
81
|
+
#Test validation on a page with a table(made using the shortcut)
|
82
|
+
def test_valid_page_with_table_shortcut
|
83
|
+
page = Page.new
|
84
|
+
page.head.append(shortcut_title("Test"))
|
85
|
+
headers = ["Name", "URL"]
|
86
|
+
data = [
|
87
|
+
["Google", "http://www.google.co.uk"],
|
88
|
+
["Kanodi", "http://kanodi.com"],
|
89
|
+
["SnipIt!", "http://snipit.kanodi.com"]
|
90
|
+
]
|
91
|
+
tbl = shortcut_table(headers, data)
|
92
|
+
main = Division.new
|
93
|
+
main.append(tbl)
|
94
|
+
page.body.append(main)
|
95
|
+
f = File.new('temp/valid_table_shortcut_test.html', 'w')
|
96
|
+
f.puts page.to_html
|
97
|
+
f.close
|
98
|
+
assert(w3c_validate?('temp/valid_table_shortcut_test.html'))
|
99
|
+
end
|
24
100
|
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.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Caine
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-09 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|