simply 0.1.3

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/simply.gemspec ADDED
@@ -0,0 +1,58 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{simply}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Scott Taylor"]
9
+ s.date = %q{2009-05-07}
10
+ s.description = %q{TODO}
11
+ s.email = %q{scott@railsnewbie.com}
12
+ s.extra_rdoc_files = [
13
+ "README"
14
+ ]
15
+ s.files = [
16
+ "Rakefile",
17
+ "VERSION.yml",
18
+ "lib/simply.rb",
19
+ "lib/simply/html_builder.rb",
20
+ "lib/simply/html_tags.rb",
21
+ "lib/simply/indentation.rb",
22
+ "lib/simply/locals.rb",
23
+ "lib/simply/version.rb",
24
+ "spec/simply/html_builder/indentation_spec.rb",
25
+ "spec/simply/html_builder/locals_spec.rb",
26
+ "spec/simply/html_builder_spec.rb",
27
+ "spec/simply/indentation_spec.rb",
28
+ "spec/simply/simply_spec.rb",
29
+ "spec/simply/version_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.has_rdoc = true
34
+ s.homepage = %q{http://github.com/smtlaissezfaire/simply}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.1}
38
+ s.summary = %q{TODO}
39
+ s.test_files = [
40
+ "spec/simply/html_builder/indentation_spec.rb",
41
+ "spec/simply/html_builder/locals_spec.rb",
42
+ "spec/simply/html_builder_spec.rb",
43
+ "spec/simply/indentation_spec.rb",
44
+ "spec/simply/simply_spec.rb",
45
+ "spec/simply/version_spec.rb",
46
+ "spec/spec_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 2
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ else
55
+ end
56
+ else
57
+ end
58
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ module Simply
4
+ describe HTMLBuilder, "with indentation" do
5
+ before(:each) do
6
+ @builder = HTMLBuilder.new(:indent => true)
7
+ end
8
+
9
+ it "should be indented when passed :indent => true" do
10
+ builder = HTMLBuilder.new(:indent => true)
11
+ builder.should be_indented
12
+ end
13
+
14
+ it "should not be indented when passed :indent => false" do
15
+ builder = HTMLBuilder.new(:indent => false)
16
+ builder.should_not be_indented
17
+ end
18
+
19
+ it "should not be indented by default" do
20
+ builder = HTMLBuilder.new
21
+ builder.should_not be_indented
22
+ end
23
+
24
+ it "should indent html when indented = true, and given a block structure" do
25
+ @builder.html do
26
+ body do
27
+ end
28
+ end
29
+
30
+ @builder.to_s.should == (<<-HERE).chomp
31
+ <html>
32
+ <body>
33
+ </body>
34
+ </html>
35
+ HERE
36
+ end
37
+
38
+ it "should not indent tags which are on the same block level" do
39
+ @builder.br
40
+ @builder.br
41
+ @builder.to_s.should == "<br />\n<br />"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ module Simply
4
+ describe HTMLBuilder, "with locals" do
5
+ before(:each) do
6
+ @builder = HTMLBuilder.new
7
+ end
8
+
9
+ it "should have access to a variables value" do
10
+ @builder.locals = { :foo => "bar" }
11
+ @builder.ul do
12
+ li foo
13
+ end
14
+
15
+ @builder.to_s.should == "<ul><li>bar</li></ul>"
16
+ end
17
+
18
+ it "should convert integer keys to strings" do
19
+ @builder.locals = { :foo => 1 }
20
+ @builder.ul do
21
+ li foo
22
+ end
23
+
24
+ @builder.to_s.should == "<ul><li>1</li></ul>"
25
+ end
26
+
27
+ it "should be able to use any number of keys" do
28
+ @builder.locals = { :foo => 1, :bar => 2, :baz => 3}
29
+ @builder.ul do
30
+ li foo
31
+ li bar
32
+ li baz
33
+ end
34
+
35
+ @builder.to_s.should == "<ul><li>1</li><li>2</li><li>3</li></ul>"
36
+ end
37
+
38
+ it "should take locals in the constructor" do
39
+ builder = HTMLBuilder.new(:locals => { :foo => "bar", :bar => "baz" }) do
40
+ ul do
41
+ li foo
42
+ li bar
43
+ end
44
+ end
45
+
46
+ builder.to_s.should == "<ul><li>bar</li><li>baz</li></ul>"
47
+ end
48
+
49
+ it "should be able to pass in several sets of locals at different times" do
50
+ builder = HTMLBuilder.new(:locals => {:foo => "1"})
51
+ builder.locals = {:bar => "2"}
52
+ builder.ul do
53
+ li foo
54
+ li bar
55
+ end
56
+
57
+ builder.to_s.should == "<ul><li>1</li><li>2</li></ul>"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,148 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ module Simply
4
+ describe HTMLBuilder do
5
+ before(:each) do
6
+ @builder = HTMLBuilder.new
7
+ end
8
+
9
+ it "should create a self-closing hr tag" do
10
+ @builder.br
11
+ @builder.to_s.should == "<br />"
12
+ end
13
+
14
+ it "should create a self closing hr tag" do
15
+ @builder.hr
16
+ @builder.to_s.should == "<hr />"
17
+ end
18
+
19
+ it "should create two self-closing tags" do
20
+ @builder.br
21
+ @builder.hr
22
+ @builder.to_s.should == "<br /><hr />"
23
+ end
24
+
25
+ it "should output text directly with the text method" do
26
+ @builder.text "foo"
27
+ @builder.to_s.should == "foo"
28
+ end
29
+
30
+ it "should call to_s on the object given to text" do
31
+ obj = Object.new
32
+ obj.stub!(:to_s).and_return "foo"
33
+ @builder.text obj
34
+ @builder.to_s.should == "foo"
35
+ end
36
+
37
+ it "should have a paragraph tag" do
38
+ @builder.p "foo"
39
+ @builder.to_s.should == "<p>foo</p>"
40
+ end
41
+
42
+ it "should contain the text inside the paragraph tags" do
43
+ @builder.p "bar baz"
44
+ @builder.to_s.should == "<p>bar baz</p>"
45
+ end
46
+
47
+ it "should take options with a string given" do
48
+ @builder.p "bar baz", :class => :something
49
+
50
+ @builder.to_s.should == "<p class=\"something\">bar baz</p>"
51
+ end
52
+
53
+ it "should have a paragraph tag which takes a block" do
54
+ @builder.p do
55
+ text "foo"
56
+ end
57
+
58
+ @builder.to_s.should == "<p>foo</p>"
59
+ end
60
+
61
+ Simply::HTMLBuilder::SELF_CLOSING_TAGS.each do |tag|
62
+ it "should have the tag #{tag}" do
63
+ @builder.send(tag)
64
+ @builder.to_s.should == "<#{tag} />"
65
+ end
66
+ end
67
+
68
+ it "should set options given to a self-closing tag" do
69
+ @builder.img :src => "foo"
70
+ @builder.to_s.should == "<img src=\"foo\" />"
71
+ end
72
+
73
+ it "should set two options to a self-closing tag" do
74
+ @builder.img :src => "foo", :alt => :some_text
75
+ out = @builder.to_s
76
+ out.should =~ /<img.*alt=\"some_text\".*\/>/
77
+ out.should =~ /<img.*src=\"foo\".*\/>/
78
+ end
79
+
80
+ it "should set options on a non-self closing tag (like a p)" do
81
+ @builder.p :class => :foo, :name => :something do
82
+ text "foo"
83
+ end
84
+
85
+ @builder.to_s.should == '<p class="foo" name="something">foo</p>'
86
+ end
87
+
88
+ Simply::HTMLBuilder::BLOCK_TAGS.each do |tag|
89
+ it "should have the #{tag} tag" do
90
+ @builder.send(tag, "foo")
91
+ @builder.to_s.should == "<#{tag}>foo</#{tag}>"
92
+ end
93
+
94
+ it "should contain the text inside the #{tag} tags" do
95
+ @builder.send(tag, "bar baz")
96
+ @builder.to_s.should == "<#{tag}>bar baz</#{tag}>"
97
+ end
98
+
99
+ it "should take options with a string given" do
100
+ @builder.send(tag, "bar baz", :class => :something)
101
+
102
+ @builder.to_s.should == "<#{tag} class=\"something\">bar baz</#{tag}>"
103
+ end
104
+
105
+ it "should have a paragraph tag which takes a block" do
106
+ @builder.send(tag) do
107
+ text "foo"
108
+ end
109
+
110
+ @builder.to_s.should == "<#{tag}>foo</#{tag}>"
111
+ end
112
+ end
113
+
114
+ it "should raise an argument error when calling a closing tag with no options" do
115
+ lambda {
116
+ @builder.p
117
+ }.should raise_error(ArgumentError)
118
+ end
119
+
120
+ it "should escape special html values" do
121
+ @builder.h1 'Apples & Oranges'
122
+ @builder.to_s.should == "<h1>Apples &amp; Oranges</h1>"
123
+ end
124
+
125
+ it "should be able to generate the xhtml-transitional dtd declaration" do
126
+ @builder.xhtml_transitional
127
+ @builder.to_s.should include('<?xml version="1.0" encoding="UTF-8"?>')
128
+ @builder.to_s.should include('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
129
+ end
130
+
131
+ it "should be able to generate the xhtml strict declaration" do
132
+ @builder.xhtml_strict
133
+ @builder.to_s.should include('<?xml version="1.0" encoding="UTF-8"?>')
134
+ @builder.to_s.should include('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')
135
+ end
136
+
137
+ it "should be able to generate the xhtml frameset" do
138
+ @builder.xhtml_frameset
139
+ @builder.to_s.should include('<?xml version="1.0" encoding="UTF-8"?>')
140
+ @builder.to_s.should include('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">')
141
+ end
142
+
143
+ it "should be able to build an empty node" do
144
+ @builder.text "Add Text"
145
+ @builder.to_s.should == "Add Text"
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ module Simply
4
+ describe Indentation do
5
+ before(:each) do
6
+ @stream = ""
7
+ @stream.extend Indentation
8
+ end
9
+
10
+ it "should be able to add text to the buffer" do
11
+ @stream << "foo"
12
+ @stream.should == "foo"
13
+ end
14
+
15
+ it "should indent by two after a call to indent" do
16
+ @stream.indent
17
+ @stream << "foo"
18
+ @stream.should == " foo"
19
+ end
20
+
21
+ it "should indent multiple calls, each on new lines" do
22
+ @stream.indent
23
+ @stream << "foo"
24
+ @stream << "bar"
25
+ @stream.should == " foo\n bar"
26
+ end
27
+
28
+ it "should indent by 4, when passed 4 explicitly" do
29
+ @stream.indent(4)
30
+ @stream << "foo"
31
+ @stream.should == " foo"
32
+ end
33
+
34
+ it "should nest indentation" do
35
+ @stream << "foo do"
36
+ @stream.indent
37
+ @stream << "something do"
38
+ @stream.indent
39
+ @stream << "bar do"
40
+
41
+ @stream.should == "foo do\n something do\n bar do"
42
+ end
43
+
44
+ it "should outdent" do
45
+ @stream.indent
46
+ @stream.outdent
47
+ @stream << "foo"
48
+ @stream.should == "foo"
49
+ end
50
+
51
+ it "should outdent by the number of spaces given" do
52
+ @stream.indent(2)
53
+ @stream.indent(2)
54
+ @stream.outdent(4)
55
+ @stream << "foo"
56
+ @stream.should == "foo"
57
+ end
58
+
59
+ it "should raise an error if outdenting too far" do
60
+ @stream.indent(2)
61
+ lambda {
62
+ @stream.outdent(4)
63
+ }.should raise_error(Indentation::IndentationError, "You can't outdent before the beginning of the page")
64
+ end
65
+
66
+ it "should raise an indentation error if the page hasn't yet been indented" do
67
+ lambda {
68
+ @stream.outdent
69
+ }.should raise_error(Indentation::IndentationError)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Simply, "the method" do
4
+ it "should take a block" do
5
+ Simply do
6
+
7
+ end
8
+ end
9
+
10
+ it "should produce html with the block" do
11
+ s = Simply do
12
+ br
13
+ end
14
+
15
+ s.should == "<br />"
16
+ end
17
+
18
+ it "should pass locals in" do
19
+ s = Simply :locals => {:foo => "foo"} do
20
+ text foo
21
+ end
22
+
23
+ s.should == "foo"
24
+ end
25
+
26
+ it "should pass indentation in" do
27
+ s = Simply :indent => true do
28
+ html do
29
+ body do
30
+ p "foo"
31
+ end
32
+ end
33
+ end
34
+
35
+ s.should == (<<-HERE).chomp
36
+ <html>
37
+ <body>
38
+ <p>
39
+ foo
40
+ </p>
41
+ </body>
42
+ </html>
43
+ HERE
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Simply, "'s Version" do
4
+ it "should be at 0.1.2" do
5
+ Simply::VERSION.should == "0.1.2"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+
2
+ --color
3
+ --diff
@@ -0,0 +1,5 @@
1
+
2
+ require "rubygems"
3
+ require "spec"
4
+
5
+ require File.dirname(__FILE__) + "/../lib/simply"
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simply
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Scott Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-09 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Cleaner + smaller markaby clone.
17
+ email: scott@railsnewbie.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - .gitignore
26
+ - README
27
+ - Rakefile
28
+ - VERSION.yml
29
+ - benchmarks/001_7a22450a80d6253bf9f0aabb2ee0110c2d67c8a6.out
30
+ - benchmarks/002_e462499cd6bd8dface62e433311b3bc0b0b55a42
31
+ - benchmarks/comparison.rb
32
+ - lib/simply.rb
33
+ - lib/simply/html_builder.rb
34
+ - lib/simply/html_tags.rb
35
+ - lib/simply/indentation.rb
36
+ - lib/simply/locals.rb
37
+ - lib/simply/version.rb
38
+ - profiling/run_static.rb
39
+ - profiling/run_static_001_0e246c3de41a891c206c8cb5a552d17d78e4b8ec.out
40
+ - reference/ABOUT
41
+ - reference/xhtml1-frameset.xsd
42
+ - reference/xhtml1-strict.xsd
43
+ - reference/xhtml1-transitional.xsd
44
+ - simply.gemspec
45
+ - spec/simply/html_builder/indentation_spec.rb
46
+ - spec/simply/html_builder/locals_spec.rb
47
+ - spec/simply/html_builder_spec.rb
48
+ - spec/simply/indentation_spec.rb
49
+ - spec/simply/simply_spec.rb
50
+ - spec/simply/version_spec.rb
51
+ - spec/spec.opts
52
+ - spec/spec_helper.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/smtlaissezfaire/simply
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: A markaby-like html builder
81
+ test_files:
82
+ - spec/simply/html_builder/indentation_spec.rb
83
+ - spec/simply/html_builder/locals_spec.rb
84
+ - spec/simply/html_builder_spec.rb
85
+ - spec/simply/indentation_spec.rb
86
+ - spec/simply/simply_spec.rb
87
+ - spec/simply/version_spec.rb
88
+ - spec/spec_helper.rb