rails-block-labels 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -1,243 +1,44 @@
1
- # Shaven - Templating without mustaches!
2
-
3
- Hey guys, look at present fasion... mustaches are not fashionable anymore =P.
4
- Take a look how nice looking are shaven templates.
5
-
6
- ## Motivation
7
-
8
- I'm not a designer, usualy all templates in my work are prepared by external
9
- design studios or freelancers... But of course they are always pure xhtml.
10
- So still we have to deal with them, convert to haml, fill in with mustaches or
11
- erb sh**t! Now, my patience is over. Shaven will readmit some MVPC's fresh
12
- air to your web apps and allow you to get rid of stupid logic from your views.
13
-
14
- ## Installation
15
-
16
- Installation with rubygems should go without quirks. Shaven depends on Nokogiri - if
17
- you don't have it installed yet then i recommend you to check out its documentation
18
- to avoid problems.
19
-
20
- $ gem install shaven
21
-
22
- ## How it works?
23
-
24
- Shaven views are splited into two layers (similar to defunk's mustache) - Template
25
- and Presenter. Templates are pure html files, Presenters are ruby classes
26
- which provides data for templates. Depending on the data type provided by
27
- presenter's methods you can freely and easily manipulate all contents within
28
- your templates. Ok, lets finish talking and take a look at examples...
29
-
30
- ### Simple usage
31
-
32
- class SimplePresenter < Shaven::Presenter
33
- def title
34
- "Hello world!"
35
- end
36
-
37
- def description
38
- "Yeah, hello beautiful code..."
39
- end
40
- end
41
-
42
- html = <<-HTML
43
- <!DOCTYPE html>
44
- <html>
45
- <head>
46
- <title data-fill="title">Example title!</title>
47
- </head>
48
- <body>
49
- <h1 data-fill="title">Example title</h1>
50
- <p data-fill="description">Example description...</p>
51
- </body>
52
- </html>
53
- HTML
54
-
55
- SimplePresenter.feed(html).to_html
56
-
57
- This code produces following html:
58
-
59
- <!DOCTYPE html>
60
- <html>
61
- <head>
62
- <title>Hello World!</title>
63
- </head>
64
- <body>
65
- <h1>Hello World!</h1>
66
- <p>Yeah, hello beautiful code...</p>
67
- </body>
68
- </html>
69
-
70
- ### DOM manipulation
71
-
72
- class ManipulationPresenter < Shaven::Presenter
73
- # If you add parameter to the presenter method, original node will
74
- # passed to it. Given element is an Nokogiri::XML::Node with some
75
- # extra helpers for content manipulation.
76
- def login_link(node)
77
- node.update!(:href => logout_path, :method => "delete")
78
- end
79
-
80
- # You can use extra html helpers to create new dom elements...
81
- def home_page_link
82
- a(:href => root_path, :class => "home-page-link") { "Go home!" }
83
- end
84
-
85
- # ... or to replace current.
86
- def title(node)
87
- node.replace! { tag(:h1, :id => "header") { "This is Sparta! "} }
88
- end
89
- end
90
-
91
- html = <<-HTML
92
- <!DOCTYPE html>
93
- <html>
94
- <body>
95
- <div rb="title">Example title</div>
96
- <a href="#" data-fill="logout_link">Logout!</a>
97
- <div data-fill="home_page_link">Home page link will go here...</div>
98
- </body>
99
- </html>
100
- HTML
101
-
102
- ManipulationPresenter.feed(html).to_html
103
-
104
- Result:
105
-
106
- <!DOCTYPE html>
107
- <html>
108
- <body>
109
- <h1 id="header">This is Sparta!</h1>
110
- <a href="/logout" data-method="delete">Logout!</a>
111
- <div><a href="/" class="home-page-link">Go Home!</a></div>
112
- </body>
113
- </html>
114
-
115
- ### Hash scopes and lists
116
-
117
- Now, the true power of Shaven. Suport for lists and scopes.
118
-
119
- class ComplexPresenter < Shaven::Presenter
120
- # As scopes are treaded all hashes and objects responding to `#to_shaven`
121
- # method (which returns hash with attributes).
122
- def user
123
- { :name => "John Doe",
124
- :email => "john@doe.com",
125
- }
126
- end
127
-
128
- def users_list
129
- [ { :name => tag(:strong) { "Emmet Brown" }, :email => "emmet@brown.com"},
130
- { :name => proc { |node| node.update!(:class => "marty") { "Marty Macfly" }, :email => "marty@macfly.com" },
131
- { :name => "Biff Tannen", :email => "biff@tannen.com" }
132
- ]
133
- end
134
- end
135
-
136
- html = <<-HTML
137
- <!DOCTYPE html>
138
- <html>
139
- <body>
140
- <h1>Single user here!</h1>
141
- <div data-fill="user">
142
- <h2 data-fill="name">Sample name</h2>
143
- <p data-fill="email">sapmle@email.com</p>
144
- </div>
145
- <h1>More users</h1>
146
- <ul id="users">
147
- <li data-fill="users_list">
148
- <span data-fill="name">Sample name</span>
149
- <span data-fill="email">sample@email.com</span>
150
- <li>
151
- </ul>
152
- </body>
153
- </html>
154
- HTML
155
-
156
- And the awesome result is:
157
-
158
- <!DOCTYPE html>
159
- <html>
160
- <body>
161
- <h1>Single user here!</h1>
162
- <div data-fill="user">
163
- <h2>Adam Smith</h2>
164
- <p>adam@smith.com</p>
165
- </div>
166
- <h1>More users</h1>
167
- <ul id="users">
168
- <li>
169
- <span><strong>Emmet Brown</strong></span>
170
- <span>brown@brown.com</span>
171
- <li>
172
- <li class="marty">
173
- <span>Marty Macfly</span>
174
- <span>marty@macfly.com</span>
175
- <li>
176
- <li>
177
- <span>Biff Tannen</span>
178
- <span>biff@tannen.com</span>
179
- <li>
180
- </ul>
181
- </body>
182
- </html>
183
-
184
- ### Conditionals
185
-
186
- class ConditionalsPresenter < Shaven::Presenter
187
- def true?
188
- true
189
- end
190
-
191
- def false?
192
- false
193
- end
194
- end
195
-
196
- html = <<-HTML
197
- <!DOCTYPE html>
198
- <html>
199
- <body>
200
- <div data-if="true?">Hello...</div>
201
- <div data-unless="false?">World!</div>
202
- </body>
203
- </html>
204
- HTML
205
-
206
- ### Dummy elements
207
-
208
- html = <<-HTML
209
- <!DOCTYPE html>
210
- <html>
211
- <body>
212
- <h1>Hello dummies!</h1>
213
- <div data-dummy="yes">This is dummy text!</div>
214
- </body>
215
- </html>
216
- HTML
217
-
218
- produces:
219
-
220
- <!DOCTYPE html>
221
- <html>
222
- <body>
223
- <h1>Hello dummies!</h1>
224
- </body>
225
- </html>
226
-
227
- ## Benchmarks
228
-
229
- Ruby 1.9.2
230
-
231
- user system total real
232
- Shaven 3.480000 0.050000 3.530000 ( 3.539728)
233
- ERB 1.360000 0.010000 1.370000 ( 1.374822)
234
- Mustache 6.830000 0.080000 6.910000 ( 6.904736)
235
- HAML 10.800000 0.080000 10.880000 ( 10.886872)
236
-
237
- Ruby 1.8.7
238
-
239
- user system total real
240
- Shaven 8.510000 0.120000 8.630000 ( 8.658850)
241
- ERB 1.510000 0.010000 1.520000 ( 1.516075)
242
- Mustache 5.230000 0.070000 5.300000 ( 5.314266)
243
- HAML 13.100000 0.230000 13.330000 ( 13.337038)
1
+ # Rails Block Labels
2
+
3
+ Rails sucks at forms styling/formatting point. One nice idea to keep forms slim and easy to style
4
+ is to place inputs inside the label tag. This is hack which give you standard label behavior (eg.
5
+ i18n supoprt) with block wrapping.
6
+
7
+ ## Usage
8
+
9
+ Add to your gemfile:
10
+
11
+ gem 'rails-block-labels'
12
+
13
+ And enjoy block labels in your views, example:
14
+
15
+ <%= form_for @post do |f| %>
16
+ <%= f.label :title do %>
17
+ <% f.text_field :title %>
18
+ <% end %>
19
+ <%= f.label :content do %>
20
+ <% f.text_area :content %>
21
+ <% end %>
22
+
23
+ *ship*
24
+ <% end %>
25
+
26
+ Example above produces:
27
+
28
+ <form ...>
29
+ <label for="post_title">
30
+ Title
31
+ <input name="post[title]" ...>
32
+ </label>
33
+ ...
34
+ </form>
35
+
36
+ **IMPORTANT!** Form fields within label block can't be printed out with `<%=`. You have to use `<%` instead.
37
+ Don't ask me why, no fucking idea o_O". It's a kind of Magic... ♪♬
38
+
39
+ ## License
40
+
41
+ **THE BEER-WARE LICENSE**
42
+ <chris@nu7hat.ch> wrote this stuff. As long as you retain this notice you
43
+ can do whatever you want with this stuff. If we meet some day, and you think
44
+ this stuff is worth it, you can buy me a beer in return Chris Kowalik.
@@ -1 +1 @@
1
- require 'rails_block_labels'
1
+ require 'rails/block/labels'
@@ -1,5 +1,3 @@
1
- require 'rails'
2
-
3
1
  class ActionView::Helpers::InstanceTag
4
2
  def to_label_tag(text = nil, options = {}, &block)
5
3
  options = options.stringify_keys
@@ -1,11 +1,8 @@
1
1
  # -*- ruby -*-
2
- $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
3
- require 'shaven/version'
4
-
5
2
  Gem::Specification.new do |s|
6
3
  s.name = "rails-block-labels"
7
4
  s.rubyforge_project = "RailsBlockLabels"
8
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
9
6
  s.authors = ["Chris Kowalik"]
10
7
  s.email = ["chris@nu7hat.ch"]
11
8
  s.homepage = "http://github.com/nu7hatch/rails-block-labels"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails-block-labels
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Kowalik
@@ -38,7 +38,7 @@ files:
38
38
  - README.md
39
39
  - Rakefile
40
40
  - lib/rails-block-labels.rb
41
- - lib/rails_block_labels.rb
41
+ - lib/rails/block/labels.rb
42
42
  - rails-block-labels.gemspec
43
43
  - spec/rails_block_labels_spec.rb
44
44
  - spec/spec_helper.rb