arbre 1.0.0.rc4 → 1.2.1
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.
- checksums.yaml +7 -0
- data/.gitignore +6 -3
- data/.rubocop.yml +15 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +86 -3
- data/Gemfile +17 -5
- data/Gemfile.lock +224 -0
- data/LICENSE +20 -0
- data/README.md +43 -0
- data/Rakefile +19 -0
- data/arbre.gemspec +3 -0
- data/docs/Gemfile +2 -0
- data/docs/_config.yml +7 -0
- data/docs/_includes/footer.html +8 -0
- data/docs/_includes/google-analytics.html +16 -0
- data/docs/_includes/head.html +7 -0
- data/docs/_includes/toc.html +12 -0
- data/docs/_includes/top-menu.html +8 -0
- data/docs/_layouts/default.html +21 -0
- data/docs/index.md +106 -0
- data/docs/stylesheets/main.css +1152 -0
- data/lib/arbre/context.rb +34 -3
- data/lib/arbre/element/builder_methods.rb +4 -5
- data/lib/arbre/element/proxy.rb +28 -0
- data/lib/arbre/element.rb +12 -6
- data/lib/arbre/element_collection.rb +1 -1
- data/lib/arbre/html/attributes.rb +11 -2
- data/lib/arbre/html/class_list.rb +4 -0
- data/lib/arbre/html/document.rb +1 -1
- data/lib/arbre/html/html5_elements.rb +4 -4
- data/lib/arbre/html/tag.rb +24 -9
- data/lib/arbre/html/text_node.rb +4 -0
- data/lib/arbre/rails/forms.rb +70 -67
- data/lib/arbre/rails/template_handler.rb +7 -5
- data/lib/arbre/version.rb +1 -1
- data/spec/arbre/integration/html_spec.rb +118 -110
- data/spec/arbre/unit/component_spec.rb +9 -9
- data/spec/arbre/unit/context_spec.rb +8 -8
- data/spec/arbre/unit/element_finder_methods_spec.rb +44 -29
- data/spec/arbre/unit/element_spec.rb +64 -45
- data/spec/arbre/unit/html/class_list_spec.rb +16 -0
- data/spec/arbre/unit/html/tag_attributes_spec.rb +20 -18
- data/spec/arbre/unit/html/tag_spec.rb +51 -15
- data/spec/changelog_spec.rb +27 -0
- data/spec/rails/integration/forms_spec.rb +14 -30
- data/spec/rails/integration/rendering_spec.rb +46 -20
- data/spec/rails/rails_spec_helper.rb +8 -11
- data/spec/rails/stub_app/log/.gitignore +1 -1
- data/spec/rails/support/mock_person.rb +15 -0
- data/spec/rails/templates/arbre/_partial_with_assignment.arb +1 -0
- data/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb +3 -0
- data/tasks/lint.rake +69 -0
- data/tasks/release.rake +6 -0
- metadata +43 -47
- data/.DS_Store +0 -0
- data/README.rdoc +0 -69
- data/lib/.DS_Store +0 -0
data/docs/index.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
---
|
2
|
+
redirect_from: /docs/documentation.html
|
3
|
+
---
|
4
|
+
# Arbre
|
5
|
+
HTML Views in Ruby
|
6
|
+
|
7
|
+
### Introduction
|
8
|
+
|
9
|
+
Arbre is a alternate template system for [Ruby on Rails Action View](http://guides.rubyonrails.org/action_view_overview.html).
|
10
|
+
Arbre expresses HTML using a Ruby DSL, which makes it similar to the [Builder](https://github.com/tenderlove/builder) gem for XML.
|
11
|
+
Arbre was extracted from [Active Admin](https://activeadmin.info/).
|
12
|
+
|
13
|
+
An example `index.html.arb`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
html {
|
17
|
+
head {
|
18
|
+
title "Welcome page"
|
19
|
+
}
|
20
|
+
body {
|
21
|
+
para "Hello, world"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
26
|
+
The purpose of Arbre is to leave the view as Ruby objects as long as possible,
|
27
|
+
which allows an object-oriented approach including inheritance, composition, and encapsulation.
|
28
|
+
|
29
|
+
### Installation
|
30
|
+
|
31
|
+
Add gem `arbre` to your `Gemfile` and `bundle install`.
|
32
|
+
|
33
|
+
Arbre registers itself as a Rails template handler for files with an extension `.arb`.
|
34
|
+
|
35
|
+
### Tags
|
36
|
+
|
37
|
+
Arbre DSL is composed of HTML tags. Tag attributes including `id` and HTML classes are passed as a hash parameter and the tag body is passed as a block. Most HTML5 tags are implemented, including `script`, `embed` and `video`.
|
38
|
+
|
39
|
+
A special case is the paragraph tag, <p>, which is mapped to `para`.
|
40
|
+
|
41
|
+
JavaScript can be included by using `script { raw ... }`
|
42
|
+
|
43
|
+
To include text that is not immediately part of a tag use `text_node`.
|
44
|
+
|
45
|
+
### Components
|
46
|
+
|
47
|
+
Arbre DSL can be extended by defining new tags composed of other, simpler tags.
|
48
|
+
This provides a simpler alternative to nesting partials.
|
49
|
+
The recommended approach is to subclass Arbre::Component and implement a new builder method.
|
50
|
+
|
51
|
+
The builder_method defines the method that will be called to build this component
|
52
|
+
when using the DSL. The arguments passed into the builder_method will be passed
|
53
|
+
into the #build method for you.
|
54
|
+
|
55
|
+
For example:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class Panel < Arbre::Component
|
59
|
+
builder_method :panel
|
60
|
+
|
61
|
+
def build(title, attributes = {})
|
62
|
+
super(attributes)
|
63
|
+
|
64
|
+
h3(title, class: "panel-title")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
By default components are `div` tags with an HTML class corresponding to the component class name. This can be overridden by redefining the `tag_name` method.
|
70
|
+
|
71
|
+
Several examples of Arbre components are [included in Active Admin](https://activeadmin.info/12-arbre-components.html)
|
72
|
+
|
73
|
+
### Contexts
|
74
|
+
|
75
|
+
An [Arbre::Context](http://www.rubydoc.info/gems/arbre/Arbre/Context) is an object in which Arbre DSL is interpreted, providing a root for the Ruby DOM that can be [searched and manipulated](http://www.rubydoc.info/gems/arbre/Arbre/Element). A context is automatically provided when a `.arb` template or partial is loaded. Contexts can be used when developing or testing a component. Contexts are rendered by calling to_s.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
html = Arbre::Context.new do
|
79
|
+
panel "Hello World", id: "my-panel" do
|
80
|
+
span "Inside the panel"
|
81
|
+
text_node "Plain text"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
puts html.to_s # =>
|
86
|
+
```
|
87
|
+
|
88
|
+
```html
|
89
|
+
<div class='panel' id="my-panel">
|
90
|
+
<h3 class='panel-title'>Hello World</h3>
|
91
|
+
<span>Inside the panel</span>
|
92
|
+
Plain text
|
93
|
+
</div>
|
94
|
+
```
|
95
|
+
|
96
|
+
A context allows you to specify Rails template assigns, aka. 'locals' and helper methods. Templates loaded by Action View have access to all [Action View helper methods](http://guides.rubyonrails.org/action_view_overview.html#overview-of-helpers-provided-by-action-view)
|
97
|
+
|
98
|
+
### Background
|
99
|
+
|
100
|
+
Similar projects include:
|
101
|
+
- [Markaby](http://markaby.github.io/), written by \_why the luck stiff.
|
102
|
+
- [Erector](http://erector.github.io/), developed at PivotalLabs.
|
103
|
+
- [Fortitude](https://github.com/ageweke/fortitude), developed at Scribd.
|
104
|
+
- [Inesita](https://inesita.fazibear.me/) (Opal)
|
105
|
+
- [html_builder](https://github.com/crystal-lang/html_builder) (Crystal)
|
106
|
+
|