reparcs 0.1.0
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/CHANGES +10 -0
- data/LICENSE +21 -0
- data/README +22 -0
- data/Rakefile +200 -0
- data/lib/reparcs/base.rb +159 -0
- data/lib/reparcs/elements/base_elements.rb +17 -0
- data/lib/reparcs/elements/edit_elements.rb +57 -0
- data/lib/reparcs/elements/form_elements.rb +225 -0
- data/lib/reparcs/elements/hypertext_elements.rb +33 -0
- data/lib/reparcs/elements/image_elements.rb +64 -0
- data/lib/reparcs/elements/link_elements.rb +24 -0
- data/lib/reparcs/elements/list_elements.rb +151 -0
- data/lib/reparcs/elements/meta_elements.rb +21 -0
- data/lib/reparcs/elements/object_elements.rb +47 -0
- data/lib/reparcs/elements/presentation_elements.rb +175 -0
- data/lib/reparcs/elements/scripting_elements.rb +41 -0
- data/lib/reparcs/elements/structure_elements.rb +62 -0
- data/lib/reparcs/elements/stylesheet_elements.rb +18 -0
- data/lib/reparcs/elements/table_elements.rb +217 -0
- data/lib/reparcs/elements/text_elements.rb +438 -0
- data/lib/reparcs/projects.rb +54 -0
- data/lib/reparcs/shortcuts.rb +106 -0
- data/lib/reparcs/utilities.rb +4 -0
- data/lib/reparcs/xml_entities.rb +9 -0
- data/lib/reparcs.rb +46 -0
- data/test/http_helpers.rb +76 -0
- data/test/test_shortcuts.rb +49 -0
- data/test/test_validmarkup.rb +23 -0
- data/www/create_www.rb +85 -0
- metadata +87 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mime/types'
|
3
|
+
require 'net/http'
|
4
|
+
require 'CGI'
|
5
|
+
|
6
|
+
#Helpers mainly for the XHTML validation.
|
7
|
+
module HTTPHelpers
|
8
|
+
class FormField
|
9
|
+
attr_accessor :name, :value
|
10
|
+
def initialize( name, value )
|
11
|
+
@name = name
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_form_data
|
16
|
+
field = CGI::escape(@name)
|
17
|
+
"Content-Disposition: form-data; name=\"#{field}\"" +
|
18
|
+
"\r\n\r\n#{@value}\r\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class FileField
|
23
|
+
attr_accessor :name, :path, :content
|
24
|
+
def initialize( name, path, content )
|
25
|
+
@name = name
|
26
|
+
@path = path
|
27
|
+
@content = content
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_form_data
|
31
|
+
"Content-Disposition: form-data; " +
|
32
|
+
"name=\"#{CGI::escape(@name)}\"; " +
|
33
|
+
"filename=\"#{@path}\"\r\n" +
|
34
|
+
"Content-Transfer-Encoding: binary\r\n" +
|
35
|
+
"Content-Type: #{MIME::Types.type_for(@path)}" +
|
36
|
+
"\r\n\r\n#{@content}\r\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class MultipartPost
|
41
|
+
SEPARATOR = 'willvalidate-aaaaaabbbb0000'
|
42
|
+
REQ_HEADER = {
|
43
|
+
"Content-type" => "multipart/form-data, boundary=#{SEPARATOR} "
|
44
|
+
}
|
45
|
+
|
46
|
+
def self.build_form_data ( form_fields )
|
47
|
+
fields = []
|
48
|
+
form_fields.each do |key, value|
|
49
|
+
if value.instance_of?(File)
|
50
|
+
fields << FileField.new(key.to_s, value.path, value.read)
|
51
|
+
else
|
52
|
+
fields << FormField.new(key.to_s, value)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
fields.collect {|f| "--#{SEPARATOR}\r\n#{f.to_form_data}" }.join("") +
|
56
|
+
"--#{SEPARATOR}--"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def w3c_validate?(file_path)
|
61
|
+
query = MultipartPost.build_form_data(
|
62
|
+
:uploaded_file => File.new(file_path, 'r'),
|
63
|
+
:charset => '(detect automatically)',
|
64
|
+
:doctype => 'XHTML 1.0 Transitional',
|
65
|
+
:group => '0'
|
66
|
+
)
|
67
|
+
resp = Net::HTTP.start('validator.w3.org') do |http|
|
68
|
+
http.post2("/check", query, MultipartPost::REQ_HEADER)
|
69
|
+
end
|
70
|
+
if resp.read_body.include?"[Valid]"
|
71
|
+
return true
|
72
|
+
else
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'reparcs.rb'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
#Reparcs shortcut tests
|
6
|
+
class ShortcutsTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Shortcuts
|
9
|
+
include TableElements
|
10
|
+
|
11
|
+
#Tests the shortcut_table method
|
12
|
+
def test_shortcut_table
|
13
|
+
desired_html = %{
|
14
|
+
<table>
|
15
|
+
<thead>
|
16
|
+
<tr>
|
17
|
+
<th>Name</th>
|
18
|
+
<th>URL</th>
|
19
|
+
</tr>
|
20
|
+
</thead>
|
21
|
+
<tbody>
|
22
|
+
<tr>
|
23
|
+
<td>Google</td>
|
24
|
+
<td>http://www.google.co.uk</td>
|
25
|
+
</tr>
|
26
|
+
<tr>
|
27
|
+
<td>Kanodi</td>
|
28
|
+
<td>http://kanodi.com</td>
|
29
|
+
</tr>
|
30
|
+
<tr>
|
31
|
+
<td>SnipIt!</td>
|
32
|
+
<td>http://snipit.kanodi.com</td>
|
33
|
+
</tr>
|
34
|
+
</tbody>
|
35
|
+
</table>
|
36
|
+
}
|
37
|
+
desired_html = desired_html.gsub(/(\n|\t| )/, "")
|
38
|
+
headers = ["Name", "URL"]
|
39
|
+
data = [
|
40
|
+
["Google", "http://www.google.co.uk"],
|
41
|
+
["Kanodi", "http://kanodi.com"],
|
42
|
+
["SnipIt!", "http://snipit.kanodi.com"]
|
43
|
+
]
|
44
|
+
tbl = shortcut_table(headers, data)
|
45
|
+
html = tbl.to_s.gsub(/(\n|\t| )/, "")
|
46
|
+
assert(html == desired_html)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'reparcs.rb'
|
3
|
+
require 'test/http_helpers'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
#XHTML validation tests
|
7
|
+
class ValidXHTMLStrictTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include Projects
|
10
|
+
include HTTPHelpers
|
11
|
+
|
12
|
+
#Tests the blank html document created by the Page class for validation
|
13
|
+
def test_standardpage
|
14
|
+
page = Page.new
|
15
|
+
title = Title.new
|
16
|
+
title.append("Standard page test")
|
17
|
+
page.head.append(title)
|
18
|
+
f = File.new('temp/valid_standard_test.html', 'w')
|
19
|
+
f.puts page.to_s
|
20
|
+
f.close()
|
21
|
+
assert(w3c_validate?('temp/valid_standard_test.html'))
|
22
|
+
end
|
23
|
+
end
|
data/www/create_www.rb
ADDED
@@ -0,0 +1,85 @@
|
|
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()
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reparcs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lee Caine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-09 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: kanodii@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- CHANGES
|
25
|
+
- LICENSE
|
26
|
+
files:
|
27
|
+
- lib/reparcs/base.rb
|
28
|
+
- lib/reparcs/elements/base_elements.rb
|
29
|
+
- lib/reparcs/elements/edit_elements.rb
|
30
|
+
- lib/reparcs/elements/form_elements.rb
|
31
|
+
- lib/reparcs/elements/hypertext_elements.rb
|
32
|
+
- lib/reparcs/elements/image_elements.rb
|
33
|
+
- lib/reparcs/elements/link_elements.rb
|
34
|
+
- lib/reparcs/elements/list_elements.rb
|
35
|
+
- lib/reparcs/elements/meta_elements.rb
|
36
|
+
- lib/reparcs/elements/object_elements.rb
|
37
|
+
- lib/reparcs/elements/presentation_elements.rb
|
38
|
+
- lib/reparcs/elements/scripting_elements.rb
|
39
|
+
- lib/reparcs/elements/structure_elements.rb
|
40
|
+
- lib/reparcs/elements/stylesheet_elements.rb
|
41
|
+
- lib/reparcs/elements/table_elements.rb
|
42
|
+
- lib/reparcs/elements/text_elements.rb
|
43
|
+
- lib/reparcs/projects.rb
|
44
|
+
- lib/reparcs/shortcuts.rb
|
45
|
+
- lib/reparcs/utilities.rb
|
46
|
+
- lib/reparcs/xml_entities.rb
|
47
|
+
- lib/reparcs.rb
|
48
|
+
- test/http_helpers.rb
|
49
|
+
- test/test_shortcuts.rb
|
50
|
+
- test/test_validmarkup.rb
|
51
|
+
- www/create_www.rb
|
52
|
+
- Rakefile
|
53
|
+
- README
|
54
|
+
- CHANGES
|
55
|
+
- LICENSE
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://reparcs.rubyforge.org/
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --title
|
61
|
+
- Reparcs API documentation
|
62
|
+
- --main
|
63
|
+
- README
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: reparcs
|
81
|
+
rubygems_version: 1.2.0
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: XHTML generation library for Ruby
|
85
|
+
test_files:
|
86
|
+
- test/test_shortcuts.rb
|
87
|
+
- test/test_validmarkup.rb
|