arbre 1.0.0.rc4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  benchmarks
6
6
  /.rvmrc
7
7
  /tags
8
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ script: bundle exec rake
2
+ rvm:
3
+ - ree
4
+ - 1.9.2
5
+ - 1.9.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.0
2
+
3
+ * Added support for the use of `:for` with non Active Model objects
4
+
1
5
  ## 1.0.0.rc4
2
6
 
3
7
  * Fix issue where user could call `symbolize_keys!` on a
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
@@ -1,2 +1,7 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
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
@@ -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
 
@@ -1,92 +1,95 @@
1
- module SplitOpenAndCloseOn
1
+ module Arbre
2
+ module Rails
3
+ module Forms
2
4
 
3
- def split_open_and_close_on(string, match)
4
- return "" unless string && match
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
- def opening_tag
10
- @opening_tag || ""
11
- end
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
- def closing_tag
14
- @closing_tag || ""
15
- end
15
+ def select(*args)
16
+ proxy_call_to_form :select, *args
17
+ end
16
18
 
17
- end
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
- class FormBuilderProxy < Arbre::Component
20
- attr_reader :form_builder
27
+ private
21
28
 
22
- # Since label and select are Arbre Elements already, we must
23
- # override it here instead of letting method_missing
24
- # deal with it
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
- def select(*args)
30
- proxy_call_to_form :select, *args
31
- end
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
- def respond_to?(name)
34
- if form_builder && form_builder.respond_to?(name)
35
- true
36
- else
37
- super
38
- end
39
- end
41
+ end
40
42
 
41
- private
43
+ class FormForProxy < FormBuilderProxy
44
+ builder_method :form_for
42
45
 
43
- def proxy_call_to_form(method, *args, &block)
44
- text_node form_builder.send(method, *args, &block)
45
- end
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
- def method_missing(method, *args, &block)
48
- if form_builder && form_builder.respond_to?(method)
49
- proxy_call_to_form(method, *args, &block)
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
- end
55
+ def fields_for(*args, &block)
56
+ insert_tag FieldsForProxy, form_builder, *args, &block
57
+ end
56
58
 
57
- class FormForProxy < FormBuilderProxy
58
- builder_method :form_for
59
- include SplitOpenAndCloseOn
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
- def build(resource, form_options = {}, &block)
62
- form_string = helpers.form_for(resource, form_options) do |f|
63
- @form_builder = f
64
- end
65
+ def opening_tag
66
+ @opening_tag || ""
67
+ end
65
68
 
66
- split_open_and_close_on form_string, "</form>"
69
+ def closing_tag
70
+ @closing_tag || ""
71
+ end
67
72
 
68
- super(&block)
69
- end
73
+ end
70
74
 
71
- def fields_for(*args, &block)
72
- insert_tag FieldsForProxy, form_builder, *args, &block
73
- end
75
+ class FieldsForProxy < FormBuilderProxy
74
76
 
75
- end
77
+ def build(form_builder, *args, &block)
78
+ form_builder.fields_for(*args) do |f|
79
+ @form_builder = f
80
+ end
76
81
 
77
- class FieldsForProxy < FormBuilderProxy
82
+ super(&block)
83
+ end
78
84
 
79
- def build(form_builder, *args, &block)
80
- form_builder.fields_for(*args) do |f|
81
- @form_builder = f
82
- end
85
+ def to_s
86
+ children.to_s
87
+ end
83
88
 
84
- super(&block)
85
- end
89
+ end
86
90
 
87
- def to_s
88
- children.to_s
91
+ end
89
92
  end
90
-
91
93
  end
92
94
 
95
+
data/lib/arbre/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arbre
2
- VERSION = "1.0.0.rc4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
 
@@ -14,6 +14,8 @@ require 'capybara/rails'
14
14
 
15
15
  require 'spec_helper'
16
16
 
17
+ require 'rails/support/mock_person'
18
+
17
19
  # Ensure that the rails plugin is installed
18
20
  require 'arbre/rails'
19
21
 
@@ -0,0 +1,15 @@
1
+ require 'active_model'
2
+
3
+ class MockPerson
4
+ extend ActiveModel::Naming
5
+
6
+ attr_accessor :name
7
+
8
+ def persisted?
9
+ false
10
+ end
11
+
12
+ def to_key
13
+ []
14
+ end
15
+ end
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.rc4
5
- prerelease: 6
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-13 00:00:00.000000000 Z
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: &70152551527460 !ruby/object:Gem::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: *70152551527460
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: 1.3.1
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