arbre 1.0.3 → 1.3.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.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +51 -2
  3. data/README.md +25 -92
  4. data/docs/Gemfile +2 -0
  5. data/docs/_config.yml +7 -0
  6. data/docs/_includes/footer.html +8 -0
  7. data/docs/_includes/google-analytics.html +16 -0
  8. data/docs/_includes/head.html +7 -0
  9. data/docs/_includes/toc.html +12 -0
  10. data/docs/_includes/top-menu.html +8 -0
  11. data/docs/_layouts/default.html +21 -0
  12. data/docs/index.md +106 -0
  13. data/docs/stylesheets/main.css +1152 -0
  14. data/lib/arbre/context.rb +3 -2
  15. data/lib/arbre/element.rb +4 -2
  16. data/lib/arbre/element/builder_methods.rb +4 -5
  17. data/lib/arbre/html/tag.rb +4 -1
  18. data/lib/arbre/rails/template_handler.rb +4 -2
  19. data/lib/arbre/version.rb +1 -1
  20. metadata +46 -73
  21. data/.gitignore +0 -10
  22. data/.travis.yml +0 -4
  23. data/Gemfile +0 -16
  24. data/Rakefile +0 -18
  25. data/arbre.gemspec +0 -22
  26. data/spec/arbre/integration/html_spec.rb +0 -250
  27. data/spec/arbre/unit/component_spec.rb +0 -44
  28. data/spec/arbre/unit/context_spec.rb +0 -35
  29. data/spec/arbre/unit/element_finder_methods_spec.rb +0 -116
  30. data/spec/arbre/unit/element_spec.rb +0 -271
  31. data/spec/arbre/unit/html/class_list_spec.rb +0 -16
  32. data/spec/arbre/unit/html/tag_attributes_spec.rb +0 -62
  33. data/spec/arbre/unit/html/tag_spec.rb +0 -103
  34. data/spec/arbre/unit/html/text_node_spec.rb +0 -5
  35. data/spec/rails/integration/forms_spec.rb +0 -105
  36. data/spec/rails/integration/rendering_spec.rb +0 -83
  37. data/spec/rails/rails_spec_helper.rb +0 -46
  38. data/spec/rails/stub_app/config/database.yml +0 -3
  39. data/spec/rails/stub_app/config/routes.rb +0 -3
  40. data/spec/rails/stub_app/db/schema.rb +0 -3
  41. data/spec/rails/stub_app/log/.gitignore +0 -1
  42. data/spec/rails/stub_app/public/favicon.ico +0 -0
  43. data/spec/rails/support/mock_person.rb +0 -15
  44. data/spec/rails/templates/arbre/_partial.arb +0 -1
  45. data/spec/rails/templates/arbre/_partial_with_assignment.arb +0 -1
  46. data/spec/rails/templates/arbre/empty.arb +0 -0
  47. data/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb +0 -3
  48. data/spec/rails/templates/arbre/page_with_assignment.arb +0 -1
  49. data/spec/rails/templates/arbre/page_with_erb_partial.arb +0 -3
  50. data/spec/rails/templates/arbre/page_with_partial.arb +0 -3
  51. data/spec/rails/templates/arbre/simple_page.arb +0 -8
  52. data/spec/rails/templates/erb/_partial.erb +0 -1
  53. data/spec/spec_helper.rb +0 -7
  54. data/spec/support/bundle.rb +0 -4
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Arbre::HTML::ClassList do
4
-
5
- describe ".build_from_string" do
6
-
7
- it "should build a new list from a string of classes" do
8
- list = Arbre::HTML::ClassList.build_from_string("first second")
9
- expect(list.size).to eq(2)
10
-
11
- expect(list).to match_array(%w{first second})
12
- end
13
-
14
- end
15
-
16
- end
@@ -1,62 +0,0 @@
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
- expect(tag.attributes).to eq({id: "my_id"})
13
- end
14
-
15
- it "should render the attributes to html" do
16
- expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n"
17
- end
18
-
19
- it "shouldn't render attributes that are empty" do
20
- tag.class_list # initializes an empty ClassList
21
- tag.set_attribute :foo, ''
22
- tag.set_attribute :bar, nil
23
-
24
- expect(tag.to_s).to eq "<tag id=\"my_id\"></tag>\n"
25
- end
26
-
27
- it "should get an attribute value" do
28
- expect(tag.attr(:id)).to eq("my_id")
29
- end
30
-
31
- describe "#has_attribute?" do
32
- context "when the attribute exists" do
33
- it "should return true" do
34
- expect(tag.has_attribute?(:id)).to eq(true)
35
- end
36
- end
37
-
38
- context "when the attribute does not exist" do
39
- it "should return false" do
40
- expect(tag.has_attribute?(:class)).to eq(false)
41
- end
42
- end
43
- end
44
-
45
- it "should remove an attribute" do
46
- expect(tag.attributes).to eq({id: "my_id"})
47
- expect(tag.remove_attribute(:id)).to eq("my_id")
48
- expect(tag.attributes).to eq({})
49
- end
50
- end
51
-
52
- describe "rendering attributes" do
53
- it "should html safe the attribute values" do
54
- tag.set_attribute(:class, '">bad things!')
55
- expect(tag.to_s).to eq "<tag class=\"&quot;&gt;bad things!\"></tag>\n"
56
- end
57
- it "should should escape the attribute names" do
58
- tag.set_attribute(">bad", "things")
59
- expect(tag.to_s).to eq "<tag &gt;bad=\"things\"></tag>\n"
60
- end
61
- end
62
- end
@@ -1,103 +0,0 @@
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
- expect(tag.content).to eq("Hello World")
12
- end
13
-
14
- it "should set the hash of options to the attributes" do
15
- expect(tag.attributes).to eq({ id: "my_id" })
16
- end
17
- end
18
-
19
- describe "creating a tag 'for' an object" do
20
- let(:model_name){ double(singular: "resource_class")}
21
- let(:resource_class){ double(model_name: model_name) }
22
- let(:resource){ double(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
- expect(tag.id).to eq("resource_class_5")
29
- end
30
-
31
- it "should add a class name" do
32
- expect(tag.class_list).to include("resource_class")
33
- end
34
-
35
-
36
- describe "for an object that doesn't have a model_name" do
37
- let(:resource_class){ double(name: 'ResourceClass') }
38
-
39
- before do
40
- tag.build for: resource
41
- end
42
-
43
- it "should set the id to the type and id" do
44
- expect(tag.id).to eq("resource_class_5")
45
- end
46
-
47
- it "should add a class name" do
48
- expect(tag.class_list).to include("resource_class")
49
- end
50
- end
51
-
52
- describe "with a default_id_for_prefix" do
53
-
54
- let(:tag) do
55
- Class.new(Arbre::HTML::Tag) do
56
- def default_id_for_prefix
57
- "a_prefix"
58
- end
59
- end.new
60
- end
61
-
62
- it "should set the id to the type and id" do
63
- expect(tag.id).to eq("a_prefix_resource_class_5")
64
- end
65
-
66
- end
67
- end
68
-
69
- describe "css class names" do
70
-
71
- it "should add a class" do
72
- tag.add_class "hello_world"
73
- expect(tag.class_names).to eq("hello_world")
74
- end
75
-
76
- it "should remove_class" do
77
- tag.add_class "hello_world"
78
- expect(tag.class_names).to eq("hello_world")
79
- tag.remove_class "hello_world"
80
- expect(tag.class_names).to eq("")
81
- end
82
-
83
- it "should not add a class if it already exists" do
84
- tag.add_class "hello_world"
85
- tag.add_class "hello_world"
86
- expect(tag.class_names).to eq("hello_world")
87
- end
88
-
89
- it "should seperate classes with space" do
90
- tag.add_class "hello world"
91
- expect(tag.class_list.size).to eq(2)
92
- end
93
-
94
- it "should create a class list from a string" do
95
- tag = Arbre::HTML::Tag.new
96
- tag.build(class: "first-class")
97
- tag.add_class "second-class"
98
- expect(tag.class_list.size).to eq(2)
99
- end
100
-
101
- end
102
-
103
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Arbre::HTML::TextNode do
4
-
5
- end
@@ -1,105 +0,0 @@
1
- require 'rails/rails_spec_helper'
2
-
3
- describe "Building forms" do
4
-
5
- let(:assigns){ {} }
6
- let(:helpers){ mock_action_view }
7
- let(:html) { form.to_s }
8
-
9
- describe "building a simple form for" do
10
-
11
- let(:form) do
12
- arbre do
13
- form_for MockPerson.new, url: "/" do |f|
14
- f.label :name
15
- f.text_field :name
16
- end
17
- end
18
- end
19
-
20
- it "should build a form" do
21
- expect(html).to have_selector("form")
22
- end
23
-
24
- it "should include the hidden authenticity token" do
25
- expect(html).to include '<input type="hidden" name="authenticity_token" value="AUTH_TOKEN" />'
26
- end
27
-
28
- it "should create a label" do
29
- expect(html).to have_selector("form label[for=mock_person_name]")
30
- end
31
-
32
- it "should create a text field" do
33
- expect(html).to have_selector("form input[type=text]")
34
- end
35
-
36
- end
37
-
38
- describe "building a form with fields for" do
39
-
40
- let(:form) do
41
- arbre do
42
- form_for MockPerson.new, url: "/" do |f|
43
- f.label :name
44
- f.text_field :name
45
- f.fields_for :permission do |pf|
46
- pf.label :admin
47
- pf.check_box :admin
48
- end
49
- end
50
- end
51
- end
52
-
53
- it "should render nested label" do
54
- expect(html).to have_selector("form label[for=mock_person_permission_admin]", text: "Admin")
55
- end
56
-
57
- it "should render nested label" do
58
- expect(html).to have_selector("form input[type=checkbox][name='mock_person[permission][admin]']")
59
- end
60
-
61
- it "should not render a div for the proxy" do
62
- expect(html).not_to have_selector("form div.fields_for_proxy")
63
- end
64
-
65
- end
66
-
67
- describe "forms with other elements" do
68
- let(:form) do
69
- arbre do
70
- form_for MockPerson.new, url: "/" do |f|
71
-
72
- div do
73
- f.label :name
74
- f.text_field :name
75
- end
76
-
77
- para do
78
- f.label :name
79
- f.text_field :name
80
- end
81
-
82
- div class: "permissions" do
83
- f.fields_for :permission do |pf|
84
- div class: "permissions_label" do
85
- pf.label :admin
86
- end
87
- pf.check_box :admin
88
- end
89
- end
90
-
91
- end
92
- end
93
- end
94
-
95
- it "should correctly nest elements" do
96
- expect(html).to have_selector("form > p > label")
97
- end
98
-
99
- it "should correnctly nest elements within fields for" do
100
- expect(html).to have_selector("form > div.permissions > div.permissions_label label")
101
- end
102
- end
103
-
104
-
105
- end
@@ -1,83 +0,0 @@
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
-
29
- def render_partial_with_instance_variable
30
- @my_instance_var = "From Instance Var"
31
- render "arbre/page_with_arb_partial_and_assignment"
32
- end
33
- end
34
-
35
-
36
- describe TestController, "Rendering with Arbre", type: :request do
37
- let(:body){ response.body }
38
-
39
- it "should render the empty template" do
40
- get "/test/render_empty"
41
- expect(response).to be_success
42
- end
43
-
44
- it "should render a simple page" do
45
- get "/test/render_simple_page"
46
- expect(response).to be_success
47
- expect(body).to have_selector("h1", text: "Hello World")
48
- expect(body).to have_selector("p", text: "Hello again!")
49
- end
50
-
51
- it "should render an arb partial" do
52
- get "/test/render_partial"
53
- expect(response).to be_success
54
- expect(body).to eq <<-EOS
55
- <h1>Before Partial</h1>
56
- <p>Hello from a partial</p>
57
- <h2>After Partial</h2>
58
- EOS
59
- end
60
-
61
- it "should render an erb (or other) partial" do
62
- get "/test/render_erb_partial"
63
- expect(response).to be_success
64
- expect(body).to eq <<-EOS
65
- <h1>Before Partial</h1>
66
- <p>Hello from an erb partial</p>
67
- <h2>After Partial</h2>
68
- EOS
69
- end
70
-
71
- it "should render with instance variables" do
72
- get "/test/render_with_instance_variable"
73
- expect(response).to be_success
74
- expect(body).to have_selector("h1", text: "From Instance Var")
75
- end
76
-
77
- it "should render an arbre partial with assignments" do
78
- get "/test/render_partial_with_instance_variable"
79
- expect(response).to be_success
80
- expect(body).to have_selector("p", text: "Partial: From Instance Var")
81
- end
82
-
83
- end
@@ -1,46 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- require 'combustion'
5
-
6
- Combustion.path = 'spec/rails/stub_app'
7
- Combustion.initialize! :action_controller,
8
- :action_view
9
-
10
- require 'rspec/rails'
11
- require 'capybara/rspec'
12
- require 'capybara/rails'
13
-
14
- require 'spec_helper'
15
-
16
- require 'rails/support/mock_person'
17
-
18
- # Ensure that the rails plugin is installed
19
- require 'arbre/rails'
20
-
21
- Rails.application.routes.draw do
22
- get 'test/:action', controller: "test"
23
- end
24
-
25
- module AdditionalHelpers
26
-
27
- def protect_against_forgery?
28
- true
29
- end
30
-
31
- def form_authenticity_token
32
- "AUTH_TOKEN"
33
- end
34
-
35
- end
36
-
37
- def mock_action_view(assigns = {})
38
- controller = ActionView::TestCase::TestController.new
39
- ActionView::Base.send :include, ActionView::Helpers
40
- ActionView::Base.send :include, AdditionalHelpers
41
- ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
42
- end
43
-
44
- RSpec.configure do |config|
45
- config.include Capybara::RSpecMatchers
46
- end
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: db/combustion_test.sqlite
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- #
3
- end
@@ -1,3 +0,0 @@
1
- # ActiveRecord::Schema.define do
2
- # #
3
- # end
@@ -1 +0,0 @@
1
- *.log
File without changes