shaven 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +1 -0
  3. data/Isolate +12 -0
  4. data/README.md +183 -0
  5. data/Rakefile +47 -0
  6. data/lib/shaven.rb +27 -0
  7. data/lib/shaven/core_ext/hash.rb +22 -0
  8. data/lib/shaven/core_ext/object.rb +17 -0
  9. data/lib/shaven/document.rb +9 -0
  10. data/lib/shaven/helpers/html.rb +68 -0
  11. data/lib/shaven/nokogiri_ext/node.rb +86 -0
  12. data/lib/shaven/presenter.rb +90 -0
  13. data/lib/shaven/scope.rb +50 -0
  14. data/lib/shaven/transformer.rb +109 -0
  15. data/lib/shaven/transformers/auto.rb +17 -0
  16. data/lib/shaven/transformers/condition.rb +25 -0
  17. data/lib/shaven/transformers/context.rb +35 -0
  18. data/lib/shaven/transformers/dummy.rb +22 -0
  19. data/lib/shaven/transformers/list.rb +51 -0
  20. data/lib/shaven/transformers/reverse_condition.rb +25 -0
  21. data/lib/shaven/transformers/text_or_node.rb +42 -0
  22. data/lib/shaven/version.rb +13 -0
  23. data/shaven.gemspec +20 -0
  24. data/spec/benchmarks.rb +189 -0
  25. data/spec/fixtures/condition.html +5 -0
  26. data/spec/fixtures/context.html +7 -0
  27. data/spec/fixtures/dummy.html +4 -0
  28. data/spec/fixtures/list.html +6 -0
  29. data/spec/fixtures/list_of_contexts.html +6 -0
  30. data/spec/fixtures/reverse_condition.html +5 -0
  31. data/spec/fixtures/text_or_node.html +4 -0
  32. data/spec/helpers_html_spec.rb +54 -0
  33. data/spec/nokogiri_node_spec.rb +55 -0
  34. data/spec/presenter_spec.rb +36 -0
  35. data/spec/spec_helper.rb +11 -0
  36. data/spec/transformers/auto_spec.rb +34 -0
  37. data/spec/transformers/condition_spec.rb +28 -0
  38. data/spec/transformers/context_spec.rb +25 -0
  39. data/spec/transformers/dummy_spec.rb +18 -0
  40. data/spec/transformers/list_spec.rb +41 -0
  41. data/spec/transformers/reverse_condition_spec.rb +28 -0
  42. data/spec/transformers/text_or_node_spec.rb +65 -0
  43. metadata +123 -0
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ class ConditionPresenter < Shaven::Presenter
4
+ def true?
5
+ true
6
+ end
7
+
8
+ def false?
9
+ false
10
+ end
11
+ end
12
+
13
+ describe Shaven::Transformer::Condition do
14
+ subject do
15
+ Shaven::Transformer::Condition
16
+ end
17
+
18
+ it "always can be transformed" do
19
+ subject.can_be_transformed?(nil).should be_true
20
+ end
21
+
22
+ describe "transform!" do
23
+ it "removes given node when condition is false" do
24
+ p = make_presenter("condition.html", ConditionPresenter)
25
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n\n<div>This should appear!</div>\n</body></html>\n"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ class ContextPresenter < Shaven::Presenter
4
+ def user
5
+ { :name => "Marty Macfly", :email => "marty@macfly.com" }
6
+ end
7
+ end
8
+
9
+ describe Shaven::Transformer::Context do
10
+ subject do
11
+ Shaven::Transformer::Context
12
+ end
13
+
14
+ it "can be transformed when value is an Hash" do
15
+ subject.can_be_transformed?({:foo => "bar"}).should be_true
16
+ subject.can_be_transformed?(nil).should be_false
17
+ end
18
+
19
+ describe "transform!" do
20
+ it "scopes given hash value as subcontext" do
21
+ p = make_presenter("context.html", ContextPresenter)
22
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n<div>\n<h2>Marty Macfly</h2>\n<p>marty@macfly.com</p>\n</div>\n</body></html>\n"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Shaven::Transformer::Dummy do
4
+ subject do
5
+ Shaven::Transformer::Dummy
6
+ end
7
+
8
+ it "always can be transformed" do
9
+ subject.can_be_transformed?(nil).should be_true
10
+ end
11
+
12
+ describe "transform!" do
13
+ it "removes given node" do
14
+ p = make_presenter("dummy.html")
15
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n\n</body></html>\n"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ class ListPresenter < Shaven::Presenter
4
+ def users
5
+ ["Emmet Brown", "Marty Macfly", "Biff Tannen"]
6
+ end
7
+ end
8
+
9
+ class ListOfContextsPresenter < Shaven::Presenter
10
+ def users
11
+ [ {:name => proc { |node| node.replace!("Emmet Brown") }},
12
+ {:name => "Marty Macfly"},
13
+ {:name => "Biff Tannen"}
14
+ ]
15
+ end
16
+ end
17
+
18
+ describe Shaven::Transformer::List do
19
+ subject do
20
+ Shaven::Transformer::List
21
+ end
22
+
23
+ it "can be transformed when value is an Array" do
24
+ subject.can_be_transformed?(nil).should be_false
25
+ subject.can_be_transformed?([1,2,3]).should be_true
26
+ end
27
+
28
+ describe "transform!" do
29
+ it "generates sequence based on current node and fills it in with list values" do
30
+ p = make_presenter("list.html", ListPresenter)
31
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n<ul>\n<li>Emmet Brown</li>\n<li>Marty Macfly</li>\n<li>Biff Tannen</li>\n</ul>\n</body></html>\n"
32
+ end
33
+
34
+ context "when list of hashes given" do
35
+ it "generates sequence based on current node and scopes list items as subcontexts" do
36
+ p = make_presenter("list_of_contexts.html", ListOfContextsPresenter)
37
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n<ul>\n<li>Emmet Brown</li>\n<li><strong>Marty Macfly</strong></li>\n<li><strong>Biff Tannen</strong></li>\n</ul>\n</body></html>\n"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ class ReverseConditionPresenter < Shaven::Presenter
4
+ def true?
5
+ true
6
+ end
7
+
8
+ def false?
9
+ false
10
+ end
11
+ end
12
+
13
+ describe Shaven::Transformer::ReverseCondition do
14
+ subject do
15
+ Shaven::Transformer::ReverseCondition
16
+ end
17
+
18
+ it "always can be transformed" do
19
+ subject.can_be_transformed?(nil).should be_true
20
+ end
21
+
22
+ describe "transform!" do
23
+ it "removes given node when condition is true" do
24
+ p = make_presenter("reverse_condition.html", ReverseConditionPresenter)
25
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n\n<div>This should appear!</div>\n</body></html>\n"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ class TextPresenter < Shaven::Presenter
4
+ def value
5
+ "Hello World!"
6
+ end
7
+ end
8
+
9
+ class NodePresenter < Shaven::Presenter
10
+ def value
11
+ tag(:h1, :id => "title") { "Hello World!" }
12
+ end
13
+ end
14
+
15
+ class UpdatesPresenter < Shaven::Presenter
16
+ def value(node)
17
+ node.update!(:id => "hello") { "Hello World!" }
18
+ end
19
+ end
20
+
21
+ class ReplacementsPresenter < Shaven::Presenter
22
+ def value(node)
23
+ node.replace!(tag(:h1) { "Hello World!" })
24
+ end
25
+ end
26
+
27
+ describe Shaven::Transformer::TextOrNode do
28
+ subject do
29
+ Shaven::Transformer::TextOrNode
30
+ end
31
+
32
+ it "always can be transformed" do
33
+ subject.can_be_transformed?(nil).should be_true
34
+ end
35
+
36
+ describe "transform!" do
37
+ context "when text given" do
38
+ it "updates node's content" do
39
+ p = make_presenter("text_or_node.html", TextPresenter)
40
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n<div>Hello World!</div>\n</body></html>\n"
41
+ end
42
+ end
43
+
44
+ context "when node given" do
45
+ it "inserts it into current node" do
46
+ p = make_presenter("text_or_node.html", NodePresenter)
47
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n<div><h1 id=\"title\">Hello World!</h1></div>\n</body></html>\n"
48
+ end
49
+ end
50
+
51
+ context "when original node" do
52
+ it "updates it" do
53
+ p = make_presenter("text_or_node.html", UpdatesPresenter)
54
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n<div id=\"hello\">Hello World!</div>\n</body></html>\n"
55
+ end
56
+ end
57
+
58
+ context "when presenter replaces node" do
59
+ it "works properly" do
60
+ p = make_presenter("text_or_node.html", ReplacementsPresenter)
61
+ p.to_html.should == "<!DOCTYPE html>\n<html><body>\n<h1>Hello World!</h1>\n</body></html>\n"
62
+ end
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shaven
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Chris Kowalik
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-29 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 1
32
+ - 4
33
+ version: "1.4"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Shaven is templating system for logic less, and extra markup free templates.
37
+ email:
38
+ - chris@nu7hat.ch
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - .rspec
48
+ - Isolate
49
+ - README.md
50
+ - Rakefile
51
+ - lib/shaven.rb
52
+ - lib/shaven/core_ext/hash.rb
53
+ - lib/shaven/core_ext/object.rb
54
+ - lib/shaven/document.rb
55
+ - lib/shaven/helpers/html.rb
56
+ - lib/shaven/nokogiri_ext/node.rb
57
+ - lib/shaven/presenter.rb
58
+ - lib/shaven/scope.rb
59
+ - lib/shaven/transformer.rb
60
+ - lib/shaven/transformers/auto.rb
61
+ - lib/shaven/transformers/condition.rb
62
+ - lib/shaven/transformers/context.rb
63
+ - lib/shaven/transformers/dummy.rb
64
+ - lib/shaven/transformers/list.rb
65
+ - lib/shaven/transformers/reverse_condition.rb
66
+ - lib/shaven/transformers/text_or_node.rb
67
+ - lib/shaven/version.rb
68
+ - shaven.gemspec
69
+ - spec/benchmarks.rb
70
+ - spec/fixtures/condition.html
71
+ - spec/fixtures/context.html
72
+ - spec/fixtures/dummy.html
73
+ - spec/fixtures/list.html
74
+ - spec/fixtures/list_of_contexts.html
75
+ - spec/fixtures/reverse_condition.html
76
+ - spec/fixtures/text_or_node.html
77
+ - spec/helpers_html_spec.rb
78
+ - spec/nokogiri_node_spec.rb
79
+ - spec/presenter_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/transformers/auto_spec.rb
82
+ - spec/transformers/condition_spec.rb
83
+ - spec/transformers/context_spec.rb
84
+ - spec/transformers/dummy_spec.rb
85
+ - spec/transformers/list_spec.rb
86
+ - spec/transformers/reverse_condition_spec.rb
87
+ - spec/transformers/text_or_node_spec.rb
88
+ has_rdoc: true
89
+ homepage: http://github.com/nu7hatch/shaven
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project: shaven
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Shaven - templating without mustaches!
122
+ test_files: []
123
+