arbre 0.0.1 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.DS_Store +0 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +10 -1
  4. data/README.rdoc +68 -2
  5. data/arbre.gemspec +2 -0
  6. data/lib/.DS_Store +0 -0
  7. data/lib/arbre.rb +18 -0
  8. data/lib/arbre/component.rb +22 -0
  9. data/lib/arbre/context.rb +81 -0
  10. data/lib/arbre/element.rb +182 -0
  11. data/lib/arbre/element/builder_methods.rb +92 -0
  12. data/lib/arbre/element_collection.rb +25 -0
  13. data/lib/arbre/html/attributes.rb +20 -0
  14. data/lib/arbre/html/class_list.rb +24 -0
  15. data/lib/arbre/html/document.rb +42 -0
  16. data/lib/arbre/html/html5_elements.rb +47 -0
  17. data/lib/arbre/html/tag.rb +175 -0
  18. data/lib/arbre/html/text_node.rb +35 -0
  19. data/lib/arbre/rails.rb +5 -0
  20. data/lib/arbre/rails/forms.rb +92 -0
  21. data/lib/arbre/rails/rendering.rb +17 -0
  22. data/lib/arbre/rails/template_handler.rb +15 -0
  23. data/lib/arbre/version.rb +1 -1
  24. data/spec/arbre/integration/html_spec.rb +241 -0
  25. data/spec/arbre/unit/component.rb +23 -0
  26. data/spec/arbre/unit/context_spec.rb +35 -0
  27. data/spec/arbre/unit/element_finder_methods_spec.rb +101 -0
  28. data/spec/arbre/unit/element_spec.rb +252 -0
  29. data/spec/arbre/unit/html/tag_attributes_spec.rb +60 -0
  30. data/spec/arbre/unit/html/tag_spec.rb +63 -0
  31. data/spec/arbre/unit/html/text_node_spec.rb +5 -0
  32. data/spec/rails/integration/forms_spec.rb +121 -0
  33. data/spec/rails/integration/rendering_spec.rb +73 -0
  34. data/spec/rails/rails_spec_helper.rb +45 -0
  35. data/spec/rails/stub_app/config/database.yml +3 -0
  36. data/spec/rails/stub_app/config/routes.rb +3 -0
  37. data/spec/rails/stub_app/db/schema.rb +3 -0
  38. data/spec/rails/stub_app/log/.gitignore +1 -0
  39. data/spec/rails/stub_app/public/favicon.ico +0 -0
  40. data/spec/rails/templates/arbre/_partial.arb +1 -0
  41. data/spec/rails/templates/arbre/empty.arb +0 -0
  42. data/spec/rails/templates/arbre/page_with_assignment.arb +1 -0
  43. data/spec/rails/templates/arbre/page_with_erb_partial.arb +3 -0
  44. data/spec/rails/templates/arbre/page_with_partial.arb +3 -0
  45. data/spec/rails/templates/arbre/simple_page.arb +8 -0
  46. data/spec/rails/templates/erb/_partial.erb +1 -0
  47. data/spec/spec_helper.rb +7 -0
  48. data/spec/support/bundle.rb +4 -0
  49. metadata +101 -45
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arbre::HTML::Tag, "Attributes" do
4
+
5
+ let(:tag){ Arbre::HTML::Tag.new }
6
+
7
+ describe "attributes" do
8
+
9
+ before { tag.build :id => "my_id" }
10
+
11
+ it "should have an attributes hash" do
12
+ tag.attributes.should == {:id => "my_id"}
13
+ end
14
+
15
+ it "should render the attributes to html" do
16
+ tag.to_s.should == <<-HTML
17
+ <tag id="my_id"></tag>
18
+ HTML
19
+ end
20
+
21
+ it "should get an attribute value" do
22
+ tag.attr(:id).should == "my_id"
23
+ end
24
+
25
+ describe "#has_attribute?" do
26
+ context "when the attribute exists" do
27
+ it "should return true" do
28
+ tag.has_attribute?(:id).should == true
29
+ end
30
+ end
31
+
32
+ context "when the attribute does not exist" do
33
+ it "should return false" do
34
+ tag.has_attribute?(:class).should == false
35
+ end
36
+ end
37
+ end
38
+
39
+ it "should remove an attribute" do
40
+ tag.attributes.should == {:id => "my_id"}
41
+ tag.remove_attribute(:id).should == "my_id"
42
+ tag.attributes.should == {}
43
+ end
44
+ end
45
+
46
+ describe "rendering attributes" do
47
+ it "should html safe the attribute values" do
48
+ tag.set_attribute(:class, "\">bad things!")
49
+ tag.to_s.should == <<-HTML
50
+ <tag class="&quot;&gt;bad things!"></tag>
51
+ HTML
52
+ end
53
+ it "should should escape the attribute names" do
54
+ tag.set_attribute(">bad", "things")
55
+ tag.to_s.should == <<-HTML
56
+ <tag &gt;bad="things"></tag>
57
+ HTML
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arbre::HTML::Tag do
4
+
5
+ let(:tag){ Arbre::HTML::Tag.new }
6
+
7
+ describe "building a new tag" do
8
+ before { tag.build "Hello World", :id => "my_id" }
9
+
10
+ it "should set the contents to a string" do
11
+ tag.content.should == "Hello World"
12
+ end
13
+
14
+ it "should set the hash of options to the attributes" do
15
+ tag.attributes.should == { :id => "my_id" }
16
+ end
17
+ end
18
+
19
+ describe "creating a tag 'for' an object" do
20
+ let(:model_name){ mock(:singular => "resource_class")}
21
+ let(:resource_class){ mock(:model_name => model_name) }
22
+ let(:resource){ mock(:class => resource_class, :to_key => ['5'])}
23
+
24
+ before do
25
+ tag.build :for => resource
26
+ end
27
+ it "should set the id to the type and id" do
28
+ tag.id.should == "resource_class_5"
29
+ end
30
+
31
+ it "should add a class name" do
32
+ tag.class_list.should include("resource_class")
33
+ end
34
+ end
35
+
36
+ describe "css class names" do
37
+
38
+ it "should add a class" do
39
+ tag.add_class "hello_world"
40
+ tag.class_names.should == "hello_world"
41
+ end
42
+
43
+ it "should remove_class" do
44
+ tag.add_class "hello_world"
45
+ tag.class_names.should == "hello_world"
46
+ tag.remove_class "hello_world"
47
+ tag.class_names.should == ""
48
+ end
49
+
50
+ it "should not add a class if it already exists" do
51
+ tag.add_class "hello_world"
52
+ tag.add_class "hello_world"
53
+ tag.class_names.should == "hello_world"
54
+ end
55
+
56
+ it "should seperate classes with space" do
57
+ tag.add_class "hello world"
58
+ tag.class_list.size.should == 2
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arbre::HTML::TextNode do
4
+
5
+ end
@@ -0,0 +1,121 @@
1
+ require 'rails/rails_spec_helper'
2
+ require 'active_model'
3
+
4
+
5
+ class MockPerson
6
+ extend ActiveModel::Naming
7
+
8
+ attr_accessor :name
9
+
10
+ def persisted?
11
+ false
12
+ end
13
+
14
+ def to_key
15
+ []
16
+ end
17
+ end
18
+
19
+ describe "Building forms" do
20
+
21
+ let(:assigns){ {} }
22
+ let(:helpers){ mock_action_view }
23
+ let(:html) { form.to_s }
24
+
25
+ describe "building a simple form for" do
26
+
27
+ let(:form) do
28
+ arbre do
29
+ form_for MockPerson.new, :url => "/" do |f|
30
+ f.label :name
31
+ f.text_field :name
32
+ end
33
+ end
34
+ end
35
+
36
+ it "should build a form" do
37
+ html.should have_selector("form")
38
+ end
39
+
40
+ it "should include the hidden authenticity token" do
41
+ html.should have_selector("form input[type=hidden][name=authenticity_token]")
42
+ end
43
+
44
+ it "should create a label" do
45
+ html.should have_selector("form label[for=mock_person_name]")
46
+ end
47
+
48
+ it "should create a text field" do
49
+ html.should have_selector("form input[type=text]")
50
+ end
51
+
52
+ end
53
+
54
+ describe "building a form with fields for" do
55
+
56
+ let(:form) do
57
+ arbre do
58
+ form_for MockPerson.new, :url => "/" do |f|
59
+ f.label :name
60
+ f.text_field :name
61
+ f.fields_for :permission do |pf|
62
+ pf.label :admin
63
+ pf.check_box :admin
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ it "should render nested label" do
70
+ html.should have_selector("form label[for=mock_person_permission_admin]", :text => "Admin")
71
+ end
72
+
73
+ it "should render nested label" do
74
+ html.should have_selector("form input[type=checkbox][name='mock_person[permission][admin]']")
75
+ end
76
+
77
+ it "should not render a div for the proxy" do
78
+ html.should_not have_selector("form div.fields_for_proxy")
79
+ end
80
+
81
+ end
82
+
83
+ describe "forms with other elements" do
84
+ let(:form) do
85
+ arbre do
86
+ form_for MockPerson.new, :url => "/" do |f|
87
+
88
+ div do
89
+ f.label :name
90
+ f.text_field :name
91
+ end
92
+
93
+ para do
94
+ f.label :name
95
+ f.text_field :name
96
+ end
97
+
98
+ div :class => "permissions" do
99
+ f.fields_for :permission do |pf|
100
+ div :class => "permissions_label" do
101
+ pf.label :admin
102
+ end
103
+ pf.check_box :admin
104
+ end
105
+ end
106
+
107
+ end
108
+ end
109
+ end
110
+
111
+ it "should correctly nest elements" do
112
+ html.should have_selector("form > p > label")
113
+ end
114
+
115
+ it "should correnctly nest elements within fields for" do
116
+ html.should have_selector("form > div.permissions > div.permissions_label label")
117
+ end
118
+ end
119
+
120
+
121
+ end
@@ -0,0 +1,73 @@
1
+ require 'rails/rails_spec_helper'
2
+
3
+ ARBRE_VIEWS_PATH = File.expand_path("../../templates", __FILE__)
4
+
5
+ class TestController < ActionController::Base
6
+ append_view_path ARBRE_VIEWS_PATH
7
+
8
+ def render_empty
9
+ render "arbre/empty"
10
+ end
11
+
12
+ def render_simple_page
13
+ render "arbre/simple_page"
14
+ end
15
+
16
+ def render_partial
17
+ render "arbre/page_with_partial"
18
+ end
19
+
20
+ def render_erb_partial
21
+ render "arbre/page_with_erb_partial"
22
+ end
23
+
24
+ def render_with_instance_variable
25
+ @my_instance_var = "From Instance Var"
26
+ render "arbre/page_with_assignment"
27
+ end
28
+ end
29
+
30
+
31
+ describe TestController, "Rendering with Arbre", :type => :request do
32
+ let(:body){ response.body }
33
+
34
+ it "should render the empty template" do
35
+ get "/test/render_empty"
36
+ response.should be_success
37
+ end
38
+
39
+ it "should render a simple page" do
40
+ get "/test/render_simple_page"
41
+ response.should be_success
42
+ body.should have_selector("h1", :text => "Hello World")
43
+ body.should have_selector("p", :text => "Hello again!")
44
+ end
45
+
46
+ it "should render an arb partial" do
47
+ get "/test/render_partial"
48
+ response.should be_success
49
+ body.should == <<-EOS
50
+ <h1>Before Partial</h1>
51
+ <p>Hello from a partial</p>
52
+ <h2>After Partial</h2>
53
+ EOS
54
+ end
55
+
56
+ it "should render an erb (or other) partial" do
57
+ get "/test/render_erb_partial"
58
+ response.should be_success
59
+ body.should == <<-EOS
60
+ <h1>Before Partial</h1>
61
+ <p>Hello from an erb partial</p>
62
+ <h2>After Partial</h2>
63
+ EOS
64
+ end
65
+
66
+ it "should render with instance variables" do
67
+ get "test/render_with_instance_variable"
68
+ response.should be_success
69
+ body.should have_selector("h1", :text => "From Instance Var")
70
+ end
71
+
72
+
73
+ end
@@ -0,0 +1,45 @@
1
+ require 'support/bundle'
2
+
3
+ require 'capybara/rspec'
4
+
5
+ # Combustion
6
+ require 'combustion'
7
+ Combustion.path = 'spec/rails/stub_app'
8
+ Combustion.initialize! :action_controller,
9
+ :action_view,
10
+ :sprockets
11
+
12
+ require 'rspec/rails'
13
+ require 'capybara/rails'
14
+
15
+ require 'spec_helper'
16
+
17
+ # Ensure that the rails plugin is installed
18
+ require 'arbre/rails'
19
+
20
+ Rails.application.routes.draw do
21
+ match 'test/:action', :controller => "test"
22
+ end
23
+
24
+ module AdditionalHelpers
25
+
26
+ def protect_against_forgery?
27
+ true
28
+ end
29
+
30
+ def form_authenticity_token
31
+ "AUTH_TOKEN"
32
+ end
33
+
34
+ end
35
+
36
+ def mock_action_view(assigns = {})
37
+ controller = ActionView::TestCase::TestController.new
38
+ ActionView::Base.send :include, ActionView::Helpers
39
+ ActionView::Base.send :include, AdditionalHelpers
40
+ ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ config.include Capybara::RSpecMatchers
45
+ end
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ #
3
+ end
@@ -0,0 +1,3 @@
1
+ # ActiveRecord::Schema.define do
2
+ # #
3
+ # end
@@ -0,0 +1 @@
1
+ *.log
File without changes
@@ -0,0 +1 @@
1
+ para "Hello from a partial"
File without changes
@@ -0,0 +1 @@
1
+ h1 my_instance_var
@@ -0,0 +1,3 @@
1
+ h1 "Before Partial"
2
+ render "erb/partial"
3
+ h2 "After Partial"
@@ -0,0 +1,3 @@
1
+ h1 "Before Partial"
2
+ render "arbre/partial"
3
+ h2 "After Partial"
@@ -0,0 +1,8 @@
1
+ html do
2
+ head do
3
+ end
4
+ body do
5
+ h1 "Hello World"
6
+ para "Hello again!"
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ <p>Hello from an erb partial</p>
@@ -0,0 +1,7 @@
1
+ require 'support/bundle'
2
+
3
+ require 'arbre'
4
+
5
+ def arbre(&block)
6
+ Arbre::Context.new assigns, helpers, &block
7
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
+
3
+ require "bundler"
4
+ Bundler.setup
metadata CHANGED
@@ -1,74 +1,130 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: arbre
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc1
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Greg Bell
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-03 00:00:00 -07:00
19
- default_executable:
20
- dependencies: []
21
-
12
+ date: 2012-06-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70148646136380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70148646136380
22
25
  description: An Object Oriented DOM Tree in Ruby
23
- email:
26
+ email:
24
27
  - gregdbell@gmail.com
25
28
  executables: []
26
-
27
29
  extensions: []
28
-
29
30
  extra_rdoc_files: []
30
-
31
- files:
31
+ files:
32
+ - .DS_Store
32
33
  - .gitignore
33
34
  - Gemfile
34
35
  - README.rdoc
35
36
  - Rakefile
36
37
  - arbre.gemspec
38
+ - lib/.DS_Store
37
39
  - lib/arbre.rb
40
+ - lib/arbre/component.rb
41
+ - lib/arbre/context.rb
42
+ - lib/arbre/element.rb
43
+ - lib/arbre/element/builder_methods.rb
44
+ - lib/arbre/element_collection.rb
45
+ - lib/arbre/html/attributes.rb
46
+ - lib/arbre/html/class_list.rb
47
+ - lib/arbre/html/document.rb
48
+ - lib/arbre/html/html5_elements.rb
49
+ - lib/arbre/html/tag.rb
50
+ - lib/arbre/html/text_node.rb
51
+ - lib/arbre/rails.rb
52
+ - lib/arbre/rails/forms.rb
53
+ - lib/arbre/rails/rendering.rb
54
+ - lib/arbre/rails/template_handler.rb
38
55
  - lib/arbre/version.rb
39
- has_rdoc: true
40
- homepage: ""
56
+ - spec/arbre/integration/html_spec.rb
57
+ - spec/arbre/unit/component.rb
58
+ - spec/arbre/unit/context_spec.rb
59
+ - spec/arbre/unit/element_finder_methods_spec.rb
60
+ - spec/arbre/unit/element_spec.rb
61
+ - spec/arbre/unit/html/tag_attributes_spec.rb
62
+ - spec/arbre/unit/html/tag_spec.rb
63
+ - spec/arbre/unit/html/text_node_spec.rb
64
+ - spec/rails/integration/forms_spec.rb
65
+ - spec/rails/integration/rendering_spec.rb
66
+ - spec/rails/rails_spec_helper.rb
67
+ - spec/rails/stub_app/config/database.yml
68
+ - spec/rails/stub_app/config/routes.rb
69
+ - spec/rails/stub_app/db/schema.rb
70
+ - spec/rails/stub_app/log/.gitignore
71
+ - spec/rails/stub_app/public/favicon.ico
72
+ - spec/rails/templates/arbre/_partial.arb
73
+ - spec/rails/templates/arbre/empty.arb
74
+ - spec/rails/templates/arbre/page_with_assignment.arb
75
+ - spec/rails/templates/arbre/page_with_erb_partial.arb
76
+ - spec/rails/templates/arbre/page_with_partial.arb
77
+ - spec/rails/templates/arbre/simple_page.arb
78
+ - spec/rails/templates/erb/_partial.erb
79
+ - spec/spec_helper.rb
80
+ - spec/support/bundle.rb
81
+ homepage: ''
41
82
  licenses: []
42
-
43
83
  post_install_message:
44
84
  rdoc_options: []
45
-
46
- require_paths:
85
+ require_paths:
47
86
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
49
88
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- hash: 3
54
- segments:
55
- - 0
56
- version: "0"
57
- required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
94
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
95
+ requirements:
96
+ - - ! '>'
97
+ - !ruby/object:Gem::Version
98
+ version: 1.3.1
66
99
  requirements: []
67
-
68
100
  rubyforge_project:
69
- rubygems_version: 1.6.2
101
+ rubygems_version: 1.8.10
70
102
  signing_key:
71
103
  specification_version: 3
72
104
  summary: An Object Oriented DOM Tree in Ruby
73
- test_files: []
74
-
105
+ test_files:
106
+ - spec/arbre/integration/html_spec.rb
107
+ - spec/arbre/unit/component.rb
108
+ - spec/arbre/unit/context_spec.rb
109
+ - spec/arbre/unit/element_finder_methods_spec.rb
110
+ - spec/arbre/unit/element_spec.rb
111
+ - spec/arbre/unit/html/tag_attributes_spec.rb
112
+ - spec/arbre/unit/html/tag_spec.rb
113
+ - spec/arbre/unit/html/text_node_spec.rb
114
+ - spec/rails/integration/forms_spec.rb
115
+ - spec/rails/integration/rendering_spec.rb
116
+ - spec/rails/rails_spec_helper.rb
117
+ - spec/rails/stub_app/config/database.yml
118
+ - spec/rails/stub_app/config/routes.rb
119
+ - spec/rails/stub_app/db/schema.rb
120
+ - spec/rails/stub_app/log/.gitignore
121
+ - spec/rails/stub_app/public/favicon.ico
122
+ - spec/rails/templates/arbre/_partial.arb
123
+ - spec/rails/templates/arbre/empty.arb
124
+ - spec/rails/templates/arbre/page_with_assignment.arb
125
+ - spec/rails/templates/arbre/page_with_erb_partial.arb
126
+ - spec/rails/templates/arbre/page_with_partial.arb
127
+ - spec/rails/templates/arbre/simple_page.arb
128
+ - spec/rails/templates/erb/_partial.erb
129
+ - spec/spec_helper.rb
130
+ - spec/support/bundle.rb