arbre 1.0.0.rc4 → 1.0.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.
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +4 -0
- data/README.rdoc +2 -0
- data/Rakefile +5 -0
- data/lib/arbre/context.rb +31 -0
- data/lib/arbre/html/tag.rb +4 -4
- data/lib/arbre/rails/forms.rb +70 -67
- data/lib/arbre/version.rb +1 -1
- data/spec/arbre/unit/html/tag_spec.rb +17 -0
- data/spec/rails/integration/forms_spec.rb +0 -16
- data/spec/rails/rails_spec_helper.rb +2 -0
- data/spec/rails/support/mock_person.rb +15 -0
- metadata +10 -9
- data/.DS_Store +0 -0
- data/lib/.DS_Store +0 -0
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.rdoc
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
Arbre is the DOM implemented in Ruby. This project is primarily used as
|
4
4
|
the object oriented view layer in Active Admin.
|
5
5
|
|
6
|
+
{<img src="https://secure.travis-ci.org/gregbell/arbre.png?branch=master" alt="Build Status" />}[http://travis-ci.org/gregbell/arbre]
|
7
|
+
|
6
8
|
== Simple Usage
|
7
9
|
|
8
10
|
A simple example of setting up an Arbre context and creating some html
|
data/Rakefile
CHANGED
data/lib/arbre/context.rb
CHANGED
@@ -1,8 +1,39 @@
|
|
1
1
|
require 'arbre/element'
|
2
2
|
|
3
3
|
module Arbre
|
4
|
+
|
5
|
+
# The Arbre::Context class is the frontend for using Arbre.
|
6
|
+
#
|
7
|
+
# The simplest example possible:
|
8
|
+
#
|
9
|
+
# html = Arbre::Context.new do
|
10
|
+
# h1 "Hello World"
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# html.to_s #=> "<h1>Hello World</h1>"
|
14
|
+
#
|
15
|
+
# The contents of the block are instance eval'd within the Context
|
16
|
+
# object. This means that you lose context to the outside world from
|
17
|
+
# within the block. To pass local variables into the Context, use the
|
18
|
+
# assigns param.
|
19
|
+
#
|
20
|
+
# html = Arbre::Context.new({:one => 1}) do
|
21
|
+
# h1 "Your number #{one}"
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# html.to_s #=> "Your number 1"
|
25
|
+
#
|
4
26
|
class Context < Element
|
5
27
|
|
28
|
+
# Initialize a new Arbre::Context
|
29
|
+
#
|
30
|
+
# @param [Hash] assigns A hash of objecs that you would like to be
|
31
|
+
# availble as local variables within the Context
|
32
|
+
#
|
33
|
+
# @param [Object] helpers An object that has methods on it which will become
|
34
|
+
# instance methods within the context.
|
35
|
+
#
|
36
|
+
# @yield [] The block that will get instance eval'd in the context
|
6
37
|
def initialize(assigns = {}, helpers = nil, &block)
|
7
38
|
assigns = assigns || {}
|
8
39
|
@_assigns = assigns.symbolize_keys
|
data/lib/arbre/html/tag.rb
CHANGED
@@ -95,7 +95,7 @@ module Arbre
|
|
95
95
|
end
|
96
96
|
|
97
97
|
INDENT_SIZE = 2
|
98
|
-
|
98
|
+
|
99
99
|
def indent(open_tag, child_content, close_tag)
|
100
100
|
spaces = ' ' * indent_level * INDENT_SIZE
|
101
101
|
|
@@ -119,11 +119,11 @@ module Arbre
|
|
119
119
|
|
120
120
|
html
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def self_closing_tag?
|
124
124
|
%w|meta link|.include?(tag_name)
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
def no_child?
|
128
128
|
children.empty?
|
129
129
|
end
|
@@ -149,7 +149,7 @@ module Arbre
|
|
149
149
|
if record.class.respond_to?(:model_name)
|
150
150
|
record.class.model_name.singular
|
151
151
|
else
|
152
|
-
record.class.underscore.gsub("/", "_")
|
152
|
+
record.class.name.underscore.gsub("/", "_")
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
data/lib/arbre/rails/forms.rb
CHANGED
@@ -1,92 +1,95 @@
|
|
1
|
-
module
|
1
|
+
module Arbre
|
2
|
+
module Rails
|
3
|
+
module Forms
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
@opening_tag = string.split(Regexp.new("#{match}\\z")).first
|
6
|
-
@closing_tag = match
|
7
|
-
end
|
5
|
+
class FormBuilderProxy < Arbre::Component
|
6
|
+
attr_reader :form_builder
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
# Since label and select are Arbre Elements already, we must
|
9
|
+
# override it here instead of letting method_missing
|
10
|
+
# deal with it
|
11
|
+
def label(*args)
|
12
|
+
proxy_call_to_form :label, *args
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
def select(*args)
|
16
|
+
proxy_call_to_form :select, *args
|
17
|
+
end
|
16
18
|
|
17
|
-
|
19
|
+
def respond_to?(name)
|
20
|
+
if form_builder && form_builder.respond_to?(name)
|
21
|
+
true
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
18
26
|
|
19
|
-
|
20
|
-
attr_reader :form_builder
|
27
|
+
private
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def label(*args)
|
26
|
-
proxy_call_to_form :label, *args
|
27
|
-
end
|
29
|
+
def proxy_call_to_form(method, *args, &block)
|
30
|
+
text_node form_builder.send(method, *args, &block)
|
31
|
+
end
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
def method_missing(method, *args, &block)
|
34
|
+
if form_builder && form_builder.respond_to?(method)
|
35
|
+
proxy_call_to_form(method, *args, &block)
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
32
40
|
|
33
|
-
|
34
|
-
if form_builder && form_builder.respond_to?(name)
|
35
|
-
true
|
36
|
-
else
|
37
|
-
super
|
38
|
-
end
|
39
|
-
end
|
41
|
+
end
|
40
42
|
|
41
|
-
|
43
|
+
class FormForProxy < FormBuilderProxy
|
44
|
+
builder_method :form_for
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
def build(resource, form_options = {}, &block)
|
47
|
+
form_string = helpers.form_for(resource, form_options) do |f|
|
48
|
+
@form_builder = f
|
49
|
+
end
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
else
|
51
|
-
super
|
52
|
-
end
|
53
|
-
end
|
51
|
+
@opening_tag, @closing_tag = split_string_on(form_string, "</form>")
|
52
|
+
super(&block)
|
53
|
+
end
|
54
54
|
|
55
|
-
|
55
|
+
def fields_for(*args, &block)
|
56
|
+
insert_tag FieldsForProxy, form_builder, *args, &block
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
def split_string_on(string, match)
|
60
|
+
return "" unless string && match
|
61
|
+
part_1 = string.split(Regexp.new("#{match}\\z")).first
|
62
|
+
[part_1, match]
|
63
|
+
end
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
+
def opening_tag
|
66
|
+
@opening_tag || ""
|
67
|
+
end
|
65
68
|
|
66
|
-
|
69
|
+
def closing_tag
|
70
|
+
@closing_tag || ""
|
71
|
+
end
|
67
72
|
|
68
|
-
|
69
|
-
end
|
73
|
+
end
|
70
74
|
|
71
|
-
|
72
|
-
insert_tag FieldsForProxy, form_builder, *args, &block
|
73
|
-
end
|
75
|
+
class FieldsForProxy < FormBuilderProxy
|
74
76
|
|
75
|
-
|
77
|
+
def build(form_builder, *args, &block)
|
78
|
+
form_builder.fields_for(*args) do |f|
|
79
|
+
@form_builder = f
|
80
|
+
end
|
76
81
|
|
77
|
-
|
82
|
+
super(&block)
|
83
|
+
end
|
78
84
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
85
|
+
def to_s
|
86
|
+
children.to_s
|
87
|
+
end
|
83
88
|
|
84
|
-
|
85
|
-
end
|
89
|
+
end
|
86
90
|
|
87
|
-
|
88
|
-
children.to_s
|
91
|
+
end
|
89
92
|
end
|
90
|
-
|
91
93
|
end
|
92
94
|
|
95
|
+
|
data/lib/arbre/version.rb
CHANGED
@@ -32,6 +32,23 @@ describe Arbre::HTML::Tag do
|
|
32
32
|
tag.class_list.should include("resource_class")
|
33
33
|
end
|
34
34
|
|
35
|
+
|
36
|
+
describe "for an object that doesn't have a model_name" do
|
37
|
+
let(:resource_class){ mock(: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
|
+
tag.id.should == "resource_class_5"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should add a class name" do
|
48
|
+
tag.class_list.should include("resource_class")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
35
52
|
describe "with a default_id_for_prefix" do
|
36
53
|
|
37
54
|
let(:tag) do
|
@@ -1,20 +1,4 @@
|
|
1
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
2
|
|
19
3
|
describe "Building forms" do
|
20
4
|
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arbre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Greg Bell
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70180007616740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70180007616740
|
25
25
|
description: An Object Oriented DOM Tree in Ruby
|
26
26
|
email:
|
27
27
|
- gregdbell@gmail.com
|
@@ -29,14 +29,13 @@ executables: []
|
|
29
29
|
extensions: []
|
30
30
|
extra_rdoc_files: []
|
31
31
|
files:
|
32
|
-
- .DS_Store
|
33
32
|
- .gitignore
|
33
|
+
- .travis.yml
|
34
34
|
- CHANGELOG.md
|
35
35
|
- Gemfile
|
36
36
|
- README.rdoc
|
37
37
|
- Rakefile
|
38
38
|
- arbre.gemspec
|
39
|
-
- lib/.DS_Store
|
40
39
|
- lib/arbre.rb
|
41
40
|
- lib/arbre/component.rb
|
42
41
|
- lib/arbre/context.rb
|
@@ -70,6 +69,7 @@ files:
|
|
70
69
|
- spec/rails/stub_app/db/schema.rb
|
71
70
|
- spec/rails/stub_app/log/.gitignore
|
72
71
|
- spec/rails/stub_app/public/favicon.ico
|
72
|
+
- spec/rails/support/mock_person.rb
|
73
73
|
- spec/rails/templates/arbre/_partial.arb
|
74
74
|
- spec/rails/templates/arbre/empty.arb
|
75
75
|
- spec/rails/templates/arbre/page_with_assignment.arb
|
@@ -94,9 +94,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
|
-
- - ! '
|
97
|
+
- - ! '>='
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
99
|
+
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
102
|
rubygems_version: 1.8.10
|
@@ -120,6 +120,7 @@ test_files:
|
|
120
120
|
- spec/rails/stub_app/db/schema.rb
|
121
121
|
- spec/rails/stub_app/log/.gitignore
|
122
122
|
- spec/rails/stub_app/public/favicon.ico
|
123
|
+
- spec/rails/support/mock_person.rb
|
123
124
|
- spec/rails/templates/arbre/_partial.arb
|
124
125
|
- spec/rails/templates/arbre/empty.arb
|
125
126
|
- spec/rails/templates/arbre/page_with_assignment.arb
|
data/.DS_Store
DELETED
Binary file
|
data/lib/.DS_Store
DELETED
Binary file
|