crafty 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -130,7 +130,8 @@ Benchmarks
130
130
 
131
131
  Benchmarks do not necessarily give a complete picture of real-world
132
132
  performance. Nevertheless, we wish to demonstrate that Crafty is fast enough
133
- for daily use. These benchmarks were performed with Ruby 1.9.2.
133
+ for daily use. These benchmarks are the result of rendering a relatively small
134
+ template 50000 times. They were performed on Max OS X with Ruby 1.9.2.
134
135
 
135
136
  Number of iterations = 50000
136
137
  user system total real
@@ -141,6 +142,9 @@ for daily use. These benchmarks were performed with Ruby 1.9.2.
141
142
  tagz 32.860000 0.650000 33.510000 ( 33.461828)
142
143
  nokogiri 27.450000 0.210000 27.660000 ( 27.608287)
143
144
 
145
+ The implementation of these benchmarks can be found in the
146
+ [benchmark](https://github.com/voormedia/crafty/tree/master/benchmark) directory.
147
+
144
148
 
145
149
  Requirements
146
150
  ------------
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ Jeweler::Tasks.new do |spec|
10
10
  spec.authors = ["Rolf Timmermans"]
11
11
  spec.email = "r.timmermans@voormedia.com"
12
12
 
13
- spec.files -= Dir["{benchmark,src}/**/*"]
13
+ spec.files -= Dir["{benchmark,src,site}/**/*"]
14
14
  end
15
15
 
16
16
  Jeweler::GemcutterTasks.new
@@ -55,49 +55,61 @@ task :generate do
55
55
  simple_format("Toolset.define(self, %w{#{regular * " "}}" + (empty.any? ? ", %w{#{empty * " "}}" : "") + ")")
56
56
  end
57
57
 
58
- autoloading = [" # Generated HTML toolsets."]
59
- Versions.each do |version|
60
- path = "crafty/toolsets/#{version.to_s.downcase}"
58
+ def create_set(version, set, elements)
59
+ path = "crafty/toolsets/#{version.to_s.downcase}/#{set.to_s.downcase}"
61
60
  file = File.open("lib/#{path}.rb", "w+")
62
61
  file.puts "module Crafty"
63
62
  file.puts " # This toolset has been automatically generated."
64
63
  file.puts " module #{version}"
64
+ file.puts " module #{set}"
65
+ file.puts define(set, elements - Childless, elements & Childless)
66
+ file.puts " end"
67
+ file.puts " end"
68
+ file.puts " # End of generated code."
69
+ file.puts "end"
70
+ file.close
71
+ [set, path]
72
+ end
73
+
74
+ def create_builder(version, set)
75
+ path = "crafty/toolsets/#{version.to_s.downcase}/builder"
76
+ file = File.open("lib/#{path}.rb", "w+")
77
+ file.puts "module Crafty"
78
+ file.puts " # This builder has been automatically generated."
79
+ file.puts " module #{version}"
80
+ file.puts " class Builder < Crafty::Builder"
81
+ file.puts " include #{set}"
82
+ file.puts " end"
83
+ file.puts " end"
84
+ file.puts " # End of generated code."
85
+ file.puts "end"
86
+ file.close
87
+ [:Builder, path]
88
+ end
65
89
 
90
+ Versions.each do |version|
66
91
  version_elements = Object.const_get(version)
67
- Sets.each do |set|
68
- set_elements = Object.const_get(set)
69
92
 
93
+ sets = []
94
+ sets << create_set(version, :All, version_elements)
95
+ sets += Sets.collect do |set|
96
+ set_elements = Object.const_get(set)
70
97
  broken = set_elements - (HTML4 + HTML5)
71
98
  raise "Incorrect elements in set: #{broken}" if broken.any?
72
-
73
- all = version_elements & set_elements
74
-
75
- file.puts " module #{set}"
76
- file.puts define(set, all - Childless, all & Childless)
77
- file.puts " end"
78
- file.puts
99
+ create_set(version, set, version_elements & set_elements)
79
100
  end
101
+ sets << create_builder(version, :All)
80
102
 
81
- file.puts " module All"
82
- file.puts define(:All, version_elements - Childless, version_elements & Childless)
83
- file.puts " end"
84
- file.puts " end"
85
-
86
- aliases = []
87
- Aliases.each { |alt, orig| aliases << alt if orig == version }
88
- file.puts "\n #{aliases * " = "} = #{version}" if aliases.any?
89
- file.puts "end"
90
- file.close
103
+ autoloading = [
104
+ " # These load paths have been automatically generated.",
105
+ *(sets.collect { |set, path| %Q( autoload :#{set}, "#{path}") }),
106
+ " # End of generated code."] * "\n"
91
107
 
92
- ([version] + aliases).each do |mod|
93
- autoloading << %Q( autoload #{mod.inspect}, #{path.inspect})
94
- end
95
- autoloading << ""
96
- end
108
+ version_file = "lib/crafty/toolsets/#{version.to_s.downcase}.rb"
97
109
 
98
- lib = File.read("lib/crafty.rb")
99
- lib.gsub!(/^\s*#\s*Generated.*\nend/m, "\n" + autoloading.join("\n") + "end")
100
- File.open "lib/crafty.rb", "w+" do |file|
101
- file.write lib
110
+ mod = File.read(version_file)
111
+ file = File.open(version_file, "w+")
112
+ file.write mod.sub(/( module #{version}\n).*?\n?( end)/m, "\\1#{autoloading}\n\\2")
113
+ file.close
102
114
  end
103
115
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{crafty}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rolf Timmermans"]
12
- s.date = %q{2011-04-01}
12
+ s.date = %q{2011-04-19}
13
13
  s.description = %q{Crafty provides you the tools to easily and flexibly create HTML output with pure Ruby.}
14
14
  s.email = %q{r.timmermans@voormedia.com}
15
15
  s.extra_rdoc_files = [
@@ -23,12 +23,24 @@ Gem::Specification.new do |s|
23
23
  "VERSION",
24
24
  "crafty.gemspec",
25
25
  "lib/crafty.rb",
26
+ "lib/crafty/builder.rb",
26
27
  "lib/crafty/safety.rb",
27
28
  "lib/crafty/tools.rb",
28
29
  "lib/crafty/toolset.rb",
29
30
  "lib/crafty/toolsets/html4.rb",
31
+ "lib/crafty/toolsets/html4/all.rb",
32
+ "lib/crafty/toolsets/html4/basic.rb",
33
+ "lib/crafty/toolsets/html4/builder.rb",
34
+ "lib/crafty/toolsets/html4/forms.rb",
35
+ "lib/crafty/toolsets/html4/semantic.rb",
30
36
  "lib/crafty/toolsets/html5.rb",
37
+ "lib/crafty/toolsets/html5/all.rb",
38
+ "lib/crafty/toolsets/html5/basic.rb",
39
+ "lib/crafty/toolsets/html5/builder.rb",
40
+ "lib/crafty/toolsets/html5/forms.rb",
41
+ "lib/crafty/toolsets/html5/semantic.rb",
31
42
  "test/test_helper.rb",
43
+ "test/unit/builder_test.rb",
32
44
  "test/unit/html_test.rb",
33
45
  "test/unit/tools_test.rb",
34
46
  "test/unit/toolset_test.rb"
@@ -38,6 +50,7 @@ Gem::Specification.new do |s|
38
50
  s.summary = %q{Build HTML like a master craftsman.}
39
51
  s.test_files = [
40
52
  "test/test_helper.rb",
53
+ "test/unit/builder_test.rb",
41
54
  "test/unit/html_test.rb",
42
55
  "test/unit/tools_test.rb",
43
56
  "test/unit/toolset_test.rb"
@@ -1,11 +1,13 @@
1
+ # Crafty provides a set of modules that provide helper methods to create
2
+ # various HTML elements.
1
3
  module Crafty
2
4
  autoload :Tools, "crafty/tools"
3
5
  autoload :Toolset, "crafty/toolset"
6
+ autoload :Builder, "crafty/builder"
4
7
 
5
- # Generated HTML toolsets.
8
+ autoload :HTML5, "crafty/toolsets/html5"
6
9
  autoload :HTML4, "crafty/toolsets/html4"
7
- autoload :XHTML, "crafty/toolsets/html4"
8
10
 
9
- autoload :HTML5, "crafty/toolsets/html5"
10
- autoload :HTML, "crafty/toolsets/html5"
11
+ autoload :HTML, "crafty/toolsets/html5"
12
+ autoload :XHTML, "crafty/toolsets/html4"
11
13
  end
@@ -0,0 +1,29 @@
1
+ module Crafty
2
+ # Builder provides a builder-like class to construct HTML output. You can
3
+ # use builders if you don't want to include the helper modules in your
4
+ # own builder class. You can also subclass from the Builder class to easily
5
+ # create your own builders.
6
+ class Builder
7
+ class << self
8
+ def build
9
+ builder = new
10
+ yield builder
11
+ builder.to_s
12
+ end
13
+ end
14
+
15
+ attr_reader :target
16
+
17
+ def initialize(target = "")
18
+ @target = target
19
+ end
20
+
21
+ def to_s
22
+ @target.to_s
23
+ end
24
+
25
+ def <<(output)
26
+ @target << output
27
+ end
28
+ end
29
+ end
@@ -5,11 +5,14 @@ module Crafty
5
5
  class << self
6
6
  ESCAPE_SEQUENCE = { "&" => "&amp;", ">" => "&gt;", "<" => "&lt;", '"' => "&quot;" }
7
7
 
8
+ # Escape HTML/XML unsafe characters.
8
9
  def escape(content)
9
10
  return content if content.html_safe?
10
11
  content.gsub(/[&><"]/) { |char| ESCAPE_SEQUENCE[char] }
11
12
  end
12
13
 
14
+ # Formats the given hash of attributes into a string that can be used
15
+ # directly inside an HTML/XML tag.
13
16
  def format_attributes(attributes)
14
17
  return if attributes.nil?
15
18
  attributes.collect do |name, value|
@@ -23,6 +26,8 @@ module Crafty
23
26
  end.join
24
27
  end
25
28
 
29
+ # Formats the given array of parameters into a string that can be used
30
+ # directly inside an HTML/XML (entity) declaration.
26
31
  def format_parameters(parameters)
27
32
  return if parameters.nil?
28
33
  parameters.collect do |name|
@@ -31,6 +36,8 @@ module Crafty
31
36
  end.join
32
37
  end
33
38
 
39
+ # Creates a safe string buffer or wraps the given object in an object
40
+ # that acts like a safe string buffer.
34
41
  def create_stream(base)
35
42
  if base.respond_to? :<<
36
43
  SafeWrapper.new(base)
@@ -40,6 +47,10 @@ module Crafty
40
47
  end
41
48
  end
42
49
 
50
+ # Write an element with the given name, content and attributes. If
51
+ # there is no content and no block is given, a self-closing element is
52
+ # created. Provide an empty string as content to create an empty,
53
+ # non-self-closing element.
43
54
  def element!(name, content = nil, attributes = nil)
44
55
  build! do
45
56
  if content or block_given?
@@ -57,6 +68,7 @@ module Crafty
57
68
  end
58
69
  end
59
70
 
71
+ # Write a comment with the given content.
60
72
  def comment!(content)
61
73
  build! do
62
74
  @_crafted << "<!-- "
@@ -65,6 +77,8 @@ module Crafty
65
77
  end
66
78
  end
67
79
 
80
+ # Write a processing instruction with the given name and attributes.
81
+ # Without arguments, it creates a default xml processing instruction.
68
82
  def instruct!(name = nil, attributes = {})
69
83
  unless name
70
84
  name = "xml"
@@ -75,12 +89,15 @@ module Crafty
75
89
  end
76
90
  end
77
91
 
92
+ # Write a (doctype or entity) declaration with the given name and
93
+ # parameters.
78
94
  def declare!(name, *parameters)
79
95
  build! do
80
96
  @_crafted << "<!#{name}#{Tools.format_parameters(parameters)}>"
81
97
  end
82
98
  end
83
99
 
100
+ # Write the given text, escaping it if necessary.
84
101
  def text!(content)
85
102
  build! do
86
103
  @_crafted << Tools.escape(content.to_s)
@@ -88,6 +105,7 @@ module Crafty
88
105
  end
89
106
  alias_method :write!, :text!
90
107
 
108
+ # Collects all elements built inside the given block into a single string.
91
109
  def build!
92
110
  @_appended = false
93
111
  if @_crafted
@@ -1,6 +1,10 @@
1
1
  module Crafty
2
2
  module Toolset
3
3
  class << self
4
+ # Define the given elements and self-closing elements in the given
5
+ # module. The module will be modified to never overwrite existing
6
+ # methods, even if they have been defined in superclasses or other
7
+ # previously-included modules.
4
8
  def define(mod, elements = [], empty_elements = [])
5
9
  define_elements(mod, elements)
6
10
  define_empty_elements(mod, empty_elements)
@@ -23,6 +27,7 @@ module Crafty
23
27
  end
24
28
  end
25
29
 
30
+ # Define regular elements in the given module.
26
31
  def define_elements(mod, elements)
27
32
  elements.each do |element|
28
33
  mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -35,6 +40,7 @@ module Crafty
35
40
  end
36
41
  end
37
42
 
43
+ # Define empty, self-closing elements in the given module.
38
44
  def define_empty_elements(mod, elements)
39
45
  elements.each do |element|
40
46
  mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -1,31 +1,12 @@
1
1
  module Crafty
2
- # This toolset has been automatically generated.
3
2
  module HTML4
4
- module Basic
5
- Toolset.define(self, %w{a blockquote body div em h1 h2 h3 h4 h5 h6 head
6
- html li p pre small span strong table td th title tr ul}, %w{br img
7
- link})
8
- end
9
-
10
- module Forms
11
- Toolset.define(self, %w{button fieldset form label object option select
12
- textarea}, %w{input})
13
- end
14
-
15
- module Semantic
16
- Toolset.define(self, %w{abbr acronym address cite code legend menu})
17
- end
18
-
19
- module All
20
- Toolset.define(self, %w{a abbr acronym address applet b bdo big
21
- blockquote body button caption center cite code colgroup dd del dfn dir
22
- div dl dt em fieldset font form frameset h1 h2 h3 h4 h5 h6 head html i
23
- iframe ins kbd label legend li map menu noframes noscript object ol
24
- optgroup option p pre q s samp script select small span strike strong
25
- style sub sup table tbody td textarea tfoot th thead title tr tt u ul
26
- var}, %w{area base basefont br col frame hr img input isindex link meta
27
- param})
28
- end
3
+ # These load paths have been automatically generated.
4
+ autoload :All, "crafty/toolsets/html4/all"
5
+ autoload :Basic, "crafty/toolsets/html4/basic"
6
+ autoload :Forms, "crafty/toolsets/html4/forms"
7
+ autoload :Semantic, "crafty/toolsets/html4/semantic"
8
+ autoload :Builder, "crafty/toolsets/html4/builder"
9
+ # End of generated code.
29
10
  end
30
11
 
31
12
  XHTML = HTML4
@@ -0,0 +1,16 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML4
4
+ module All
5
+ Toolset.define(self, %w{a abbr acronym address applet b bdo big
6
+ blockquote body button caption center cite code colgroup dd del dfn dir
7
+ div dl dt em fieldset font form frameset h1 h2 h3 h4 h5 h6 head html i
8
+ iframe ins kbd label legend li map menu noframes noscript object ol
9
+ optgroup option p pre q s samp script select small span strike strong
10
+ style sub sup table tbody td textarea tfoot th thead title tr tt u ul
11
+ var}, %w{area base basefont br col frame hr img input isindex link meta
12
+ param})
13
+ end
14
+ end
15
+ # End of generated code.
16
+ end
@@ -0,0 +1,11 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML4
4
+ module Basic
5
+ Toolset.define(self, %w{a blockquote body div em h1 h2 h3 h4 h5 h6 head
6
+ html li p pre small span strong table td th title tr ul}, %w{br img
7
+ link})
8
+ end
9
+ end
10
+ # End of generated code.
11
+ end
@@ -0,0 +1,9 @@
1
+ module Crafty
2
+ # This builder has been automatically generated.
3
+ module HTML4
4
+ class Builder < Crafty::Builder
5
+ include All
6
+ end
7
+ end
8
+ # End of generated code.
9
+ end
@@ -0,0 +1,10 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML4
4
+ module Forms
5
+ Toolset.define(self, %w{button fieldset form label object option select
6
+ textarea}, %w{input})
7
+ end
8
+ end
9
+ # End of generated code.
10
+ end
@@ -0,0 +1,9 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML4
4
+ module Semantic
5
+ Toolset.define(self, %w{abbr acronym address cite code legend menu})
6
+ end
7
+ end
8
+ # End of generated code.
9
+ end
@@ -1,33 +1,12 @@
1
1
  module Crafty
2
- # This toolset has been automatically generated.
3
2
  module HTML5
4
- module Basic
5
- Toolset.define(self, %w{a blockquote body div em h1 h2 h3 h4 h5 h6 head
6
- html li p pre small span strong table td th title tr ul}, %w{br img
7
- link})
8
- end
9
-
10
- module Forms
11
- Toolset.define(self, %w{button datalist fieldset form label meter object
12
- option output progress select textarea}, %w{input keygen})
13
- end
14
-
15
- module Semantic
16
- Toolset.define(self, %w{abbr address article cite code details figcaption
17
- figure footer header legend menu nav section}, %w{command})
18
- end
19
-
20
- module All
21
- Toolset.define(self, %w{a abbr address article aside audio b bdi bdo
22
- blockquote body button canvas caption cite code colgroup datalist dd del
23
- details dfn div dl dt em fieldset figcaption figure footer form h1 h2 h3
24
- h4 h5 h6 head header hgroup html i iframe ins kbd label legend li map
25
- mark menu meter nav noscript object ol optgroup option output p pre
26
- progress q rp rt ruby s samp script section select small span strong
27
- style sub summary sup table tbody td textarea tfoot th thead time title
28
- tr ul var video}, %w{area base br col command embed hr img input keygen
29
- link meta param source track wbr})
30
- end
3
+ # These load paths have been automatically generated.
4
+ autoload :All, "crafty/toolsets/html5/all"
5
+ autoload :Basic, "crafty/toolsets/html5/basic"
6
+ autoload :Forms, "crafty/toolsets/html5/forms"
7
+ autoload :Semantic, "crafty/toolsets/html5/semantic"
8
+ autoload :Builder, "crafty/toolsets/html5/builder"
9
+ # End of generated code.
31
10
  end
32
11
 
33
12
  HTML = HTML5
@@ -0,0 +1,17 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML5
4
+ module All
5
+ Toolset.define(self, %w{a abbr address article aside audio b bdi bdo
6
+ blockquote body button canvas caption cite code colgroup datalist dd del
7
+ details dfn div dl dt em fieldset figcaption figure footer form h1 h2 h3
8
+ h4 h5 h6 head header hgroup html i iframe ins kbd label legend li map
9
+ mark menu meter nav noscript object ol optgroup option output p pre
10
+ progress q rp rt ruby s samp script section select small span strong
11
+ style sub summary sup table tbody td textarea tfoot th thead time title
12
+ tr ul var video}, %w{area base br col command embed hr img input keygen
13
+ link meta param source track wbr})
14
+ end
15
+ end
16
+ # End of generated code.
17
+ end
@@ -0,0 +1,11 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML5
4
+ module Basic
5
+ Toolset.define(self, %w{a blockquote body div em h1 h2 h3 h4 h5 h6 head
6
+ html li p pre small span strong table td th title tr ul}, %w{br img
7
+ link})
8
+ end
9
+ end
10
+ # End of generated code.
11
+ end
@@ -0,0 +1,9 @@
1
+ module Crafty
2
+ # This builder has been automatically generated.
3
+ module HTML5
4
+ class Builder < Crafty::Builder
5
+ include All
6
+ end
7
+ end
8
+ # End of generated code.
9
+ end
@@ -0,0 +1,10 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML5
4
+ module Forms
5
+ Toolset.define(self, %w{button datalist fieldset form label meter object
6
+ option output progress select textarea}, %w{input keygen})
7
+ end
8
+ end
9
+ # End of generated code.
10
+ end
@@ -0,0 +1,10 @@
1
+ module Crafty
2
+ # This toolset has been automatically generated.
3
+ module HTML5
4
+ module Semantic
5
+ Toolset.define(self, %w{abbr address article cite code details figcaption
6
+ figure footer header legend menu nav section}, %w{command})
7
+ end
8
+ end
9
+ # End of generated code.
10
+ end
@@ -0,0 +1,67 @@
1
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
2
+
3
+ class BuilderTest < Test::Unit::TestCase
4
+ def setup
5
+ @klass = Class.new(Crafty::Builder) { include Crafty::HTML::All }
6
+ @builder = @klass.new
7
+ end
8
+
9
+ # Basic builder functionality ==============================================
10
+ test "element should build element with given name" do
11
+ @builder.element!("el")
12
+ assert_equal %Q{<el/>}, @builder.to_s
13
+ end
14
+
15
+ test "target should return given target with appended content" do
16
+ @builder.element!("el")
17
+ assert_equal %Q{<el/>}, @builder.target
18
+ end
19
+
20
+ test "div should build content with given attributes" do
21
+ @builder.div("Hello", :class => "green")
22
+ assert_equal %Q{<div class="green">Hello</div>}, @builder.to_s
23
+ end
24
+
25
+ test "build should yield builder and return built content" do
26
+ result = @klass.build do |b|
27
+ b.div :class => "green" do
28
+ b.em "Hello"
29
+ end
30
+ end
31
+ assert_equal %Q{<div class="green"><em>Hello</em></div>}, result
32
+ end
33
+
34
+ # Examples ===============================================================
35
+ test "complex nested build calls should build correctly" do
36
+ b = @builder
37
+ b.html do
38
+ b.head do
39
+ b.title "my document"
40
+ b.link :href => "style.css", :rel => :stylesheet, :type => "text/css"
41
+ end
42
+ b.body :class => :awesome do
43
+ b.div {
44
+ b.div {
45
+ b.table :cellspacing => 0 do
46
+ b.tr {
47
+ b.th "Col 1"
48
+ b.th "Col 2"
49
+ }
50
+ b.tr {
51
+ b.td 10_000
52
+ b.td "content"
53
+ }
54
+ end
55
+ }
56
+ }
57
+ end
58
+ end
59
+ assert_equal %Q{<html>} +
60
+ %Q{<head><title>my document</title><link href="style.css" rel="stylesheet" type="text/css"/></head>} +
61
+ %Q{<body class="awesome"><div><div><table cellspacing="0">} +
62
+ %Q{<tr><th>Col 1</th><th>Col 2</th></tr>} +
63
+ %Q{<tr><td>10000</td><td>content</td></tr>} +
64
+ %Q{</table></div></div></body>} +
65
+ %Q{</html>}, @builder.to_s
66
+ end
67
+ end
@@ -94,13 +94,49 @@ class HTMLBase < Test::Unit::TestCase
94
94
  end
95
95
  }
96
96
  end
97
+
98
+ # Builders ===============================================================
99
+ test "builder should build html" do
100
+ out = @html::Builder.build do |b|
101
+ b.html do
102
+ b.head do
103
+ b.title "my document"
104
+ b.link :href => "style.css", :rel => :stylesheet, :type => "text/css"
105
+ end
106
+ b.body :class => :awesome do
107
+ b.div {
108
+ b.div {
109
+ b.table :cellspacing => 0 do
110
+ b.tr {
111
+ b.th "Col 1"
112
+ b.th "Col 2"
113
+ }
114
+ b.tr {
115
+ b.td 10_000
116
+ b.td "content"
117
+ }
118
+ end
119
+ }
120
+ }
121
+ end
122
+ end
123
+ end
124
+ assert_equal %Q{<html>} +
125
+ %Q{<head><title>my document</title><link href="style.css" rel="stylesheet" type="text/css"/></head>} +
126
+ %Q{<body class="awesome"><div><div><table cellspacing="0">} +
127
+ %Q{<tr><th>Col 1</th><th>Col 2</th></tr>} +
128
+ %Q{<tr><td>10000</td><td>content</td></tr>} +
129
+ %Q{</table></div></div></body>} +
130
+ %Q{</html>}, out
131
+ end
97
132
  end
98
133
  end
99
134
 
100
135
  class HTML5Test < HTMLBase
101
136
  def setup
102
- @object = Class.new { include Crafty::HTML5::Basic }.new
103
- @streaming_object = Class.new(Array) { include Crafty::HTML5::Basic }.new
137
+ @html = html = Crafty::HTML5
138
+ @object = Class.new { include html::Basic }.new
139
+ @streaming_object = Class.new(Array) { include html::Basic }.new
104
140
  end
105
141
 
106
142
  behaves_as_basic_html
@@ -108,8 +144,9 @@ end
108
144
 
109
145
  class HTML4Test < HTMLBase
110
146
  def setup
111
- @object = Class.new { include Crafty::HTML4::Basic }.new
112
- @streaming_object = Class.new(Array) { include Crafty::HTML4::Basic }.new
147
+ @html = html = Crafty::HTML4
148
+ @object = Class.new { include html::Basic }.new
149
+ @streaming_object = Class.new(Array) { include html::Basic }.new
113
150
  end
114
151
 
115
152
  behaves_as_basic_html
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: crafty
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rolf Timmermans
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-01 00:00:00 +02:00
13
+ date: 2011-04-19 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -30,12 +30,24 @@ files:
30
30
  - VERSION
31
31
  - crafty.gemspec
32
32
  - lib/crafty.rb
33
+ - lib/crafty/builder.rb
33
34
  - lib/crafty/safety.rb
34
35
  - lib/crafty/tools.rb
35
36
  - lib/crafty/toolset.rb
36
37
  - lib/crafty/toolsets/html4.rb
38
+ - lib/crafty/toolsets/html4/all.rb
39
+ - lib/crafty/toolsets/html4/basic.rb
40
+ - lib/crafty/toolsets/html4/builder.rb
41
+ - lib/crafty/toolsets/html4/forms.rb
42
+ - lib/crafty/toolsets/html4/semantic.rb
37
43
  - lib/crafty/toolsets/html5.rb
44
+ - lib/crafty/toolsets/html5/all.rb
45
+ - lib/crafty/toolsets/html5/basic.rb
46
+ - lib/crafty/toolsets/html5/builder.rb
47
+ - lib/crafty/toolsets/html5/forms.rb
48
+ - lib/crafty/toolsets/html5/semantic.rb
38
49
  - test/test_helper.rb
50
+ - test/unit/builder_test.rb
39
51
  - test/unit/html_test.rb
40
52
  - test/unit/tools_test.rb
41
53
  - test/unit/toolset_test.rb
@@ -69,6 +81,7 @@ specification_version: 3
69
81
  summary: Build HTML like a master craftsman.
70
82
  test_files:
71
83
  - test/test_helper.rb
84
+ - test/unit/builder_test.rb
72
85
  - test/unit/html_test.rb
73
86
  - test/unit/tools_test.rb
74
87
  - test/unit/toolset_test.rb