bootstrap-shoehorn 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +9 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/README.md +336 -0
  6. data/Rakefile +32 -0
  7. data/lib/shoehorn.rb +15 -0
  8. data/lib/shoehorn/components.rb +17 -0
  9. data/lib/shoehorn/components/alert.rb +69 -0
  10. data/lib/shoehorn/components/badge.rb +38 -0
  11. data/lib/shoehorn/components/base.rb +18 -0
  12. data/lib/shoehorn/components/button.rb +72 -0
  13. data/lib/shoehorn/components/dropdown.rb +55 -0
  14. data/lib/shoehorn/components/form.rb +14 -0
  15. data/lib/shoehorn/components/form/input_field.rb +53 -0
  16. data/lib/shoehorn/components/form/label.rb +8 -0
  17. data/lib/shoehorn/components/form_builder.rb +13 -0
  18. data/lib/shoehorn/components/icon.rb +40 -0
  19. data/lib/shoehorn/components/label.rb +39 -0
  20. data/lib/shoehorn/components/modal.rb +62 -0
  21. data/lib/shoehorn/components/navigation.rb +47 -0
  22. data/lib/shoehorn/components/progress_bar.rb +51 -0
  23. data/lib/shoehorn/engine.rb +19 -0
  24. data/lib/shoehorn/helper_collection.rb +58 -0
  25. data/lib/shoehorn/helper_collection_set.rb +18 -0
  26. data/lib/shoehorn/helpers.rb +14 -0
  27. data/lib/shoehorn/helpers/alert_helpers.rb +37 -0
  28. data/lib/shoehorn/helpers/badge_helpers.rb +38 -0
  29. data/lib/shoehorn/helpers/button_helpers.rb +122 -0
  30. data/lib/shoehorn/helpers/form_helpers.rb +11 -0
  31. data/lib/shoehorn/helpers/icon_helpers.rb +34 -0
  32. data/lib/shoehorn/helpers/label_helpers.rb +37 -0
  33. data/lib/shoehorn/helpers/modal_helpers.rb +43 -0
  34. data/lib/shoehorn/helpers/navigation_helpers.rb +32 -0
  35. data/lib/shoehorn/helpers/progress_bar_helpers.rb +25 -0
  36. data/lib/shoehorn/plugins.rb +6 -0
  37. data/lib/shoehorn/plugins/simple_navigation/renderer/bootstrap_topbar_list.rb +72 -0
  38. data/lib/shoehorn/version.rb +3 -0
  39. data/log/development.log +0 -0
  40. data/shoehorn.gemspec +33 -0
  41. data/spec/helpers/alert_helpers_spec.rb +138 -0
  42. data/spec/helpers/button_helpers_spec.rb +102 -0
  43. data/spec/helpers/form_helpers_spec.rb +136 -0
  44. data/spec/helpers/inline_label_helpers_spec.rb +50 -0
  45. data/spec/helpers/modal_helpers_spec.rb +60 -0
  46. data/spec/helpers/navigation_helpers_spec.rb +61 -0
  47. data/spec/helpers/progress_bar_helpers_spec.rb +34 -0
  48. data/spec/integration/action_view_spec.rb +23 -0
  49. data/spec/integration/readme_spec.rb +14 -0
  50. data/spec/plugins/bootstrap_topbar_list_spec.rb +11 -0
  51. data/spec/spec_helper.rb +11 -0
  52. data/spec/support/bootstrap_button_macros.rb +8 -0
  53. data/spec/support/bootstrap_form_macros.rb +8 -0
  54. data/spec/support/bootstrap_modal_macros.rb +8 -0
  55. data/spec/support/bootstrap_navigation_macros.rb +8 -0
  56. data/spec/support/bootstrap_spec_helper.rb +50 -0
  57. data/spec/support/test_environment.rb +23 -0
  58. metadata +265 -0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ .bundle
3
+ Gemfile.lock
4
+ .yardoc
5
+ doc
6
+ pkg
7
+ .idea
8
+ .rvmrc
9
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --order rand
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ #- ree
5
+ - 1.9.2
6
+ - 1.9.3
7
+ #- jruby
8
+ - rbx
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bootstrap-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,336 @@
1
+ # Shoehorn: a Twitter Bootstrap 2.0 helper library for Rails
2
+
3
+ This gem focuses on making it easier to use Twitter's Bootstrap 2.0.
4
+ It's a collection of helpers which should make it faster to use all the components provided by Twitter Bootstrap.
5
+
6
+ The gem started as a fork of pusewicz's twitter-bootstrap-markup-rails gem (https://github.com/pusewicz/twitter-bootstrap-markup-rails),
7
+ but I need more customization. So I borrowed the gem structure and some code for developing Shoehorn.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem 'shoehorn'
16
+ ```
17
+
18
+ ## Currently Supported
19
+
20
+ * Alert messages
21
+ * Inline labels
22
+ * Buttons
23
+ * Button dropdowns
24
+ * link_to
25
+ * Badges
26
+ * Modal windows
27
+ * Navigation (tabs, pills)
28
+ * Progress bars
29
+
30
+
31
+ Examples
32
+ ---
33
+
34
+ ### Rendering Alert
35
+
36
+ ```ruby
37
+ bootstrap_alert("Hello!")
38
+ # => '<div class="alert"><a class="close">×</a>Hello!</div>'
39
+ ```
40
+
41
+ Rendering Info Block Alert
42
+
43
+ ```ruby
44
+ bootstrap_alert("Hello!", type: 'info', block: true)
45
+ # => '<div class="alert alert-block alert-info"><a class="close">×</a>Hello!</div>'
46
+ ```
47
+
48
+ Add Alert heading:
49
+
50
+ ```ruby
51
+ bootstrap_alert("Content of alert", heading: "WARNING!", type: 'info')
52
+ # => '<div class="alert alert-info"><a class="close">×</a><h4 class="alert-heading">WARNING!</h4>Content of alert</div>'
53
+ ```
54
+
55
+ Remove closing button
56
+
57
+ ```ruby
58
+ bootstrap_alert("Hello!", type: 'error', close: false)
59
+ # => '<div class="alert alert-error">Hello!</div>'
60
+ ```
61
+
62
+
63
+ ### Notice Inline Label
64
+
65
+ Normal label
66
+
67
+ ```ruby
68
+ bootstrap_label("Hello!")
69
+ # => '<span class="label">Hello!</span>'
70
+ ```
71
+
72
+ Change type (available values are: info, success, warning, important or inverse)
73
+
74
+ ```ruby
75
+ bootstrap_label("Hello!", type: 'warning')
76
+ # => '<span class="label label-warning">Hello!</span>'
77
+ ```
78
+
79
+ Add custom CSS class
80
+
81
+ ```ruby
82
+ bootstrap_label("Hello!", type: 'important', class: "my_awesome_class")
83
+ # => '<span class="my_awesome_class label label-important">Hello!</span>'
84
+ ```
85
+
86
+ Customize Bootstrap CSS class prefix (really needed???)
87
+
88
+ ```ruby
89
+ bootstrap_label("Hello!", type: 'info', bootstrap_class_prefix: "my_label")
90
+ # => '<span class="my_label my_label-info">Hello!</span>'
91
+ ```
92
+
93
+ ### Notice Badge
94
+
95
+ Normal badge
96
+
97
+ ```ruby
98
+ bootstrap_badge("Hello!")
99
+ # => '<span class="badge">Hello!</span>'
100
+ ```
101
+
102
+ Change type (available values are: info, success, warning, important or inverse)
103
+
104
+ ```ruby
105
+ bootstrap_badge("Hello!", type: 'success')
106
+ # => '<span class="badge badge-success">Hello!</span>'
107
+ ```
108
+
109
+ Add custom CSS class
110
+
111
+ ```ruby
112
+ bootstrap_badge("Hello!", type: 'warning', class: "my_awesome_class")
113
+ # => '<span class="my_awesome_class badge badge-warning">Hello!</span>'
114
+ ```
115
+
116
+ Customize Bootstrap CSS class prefix (really needed???)
117
+
118
+ ```ruby
119
+ bootstrap_label("Hello!", type: 'info', bootstrap_class_prefix: "my_label")
120
+ # => '<span class="my_label my_label-info">Hello!</span>'
121
+ ```
122
+
123
+ ### Icon inline
124
+
125
+ ```ruby
126
+ bootstrap_icon(name: 'user', icon_white: true)
127
+ # # => '<i class="icon-user icon-white"></i>'
128
+ ```
129
+
130
+ ```ruby
131
+ bootstrap_icon(text: "Current time", name: 'time')
132
+ # => '<i class="icon-time"></i> Current time'
133
+ ```
134
+
135
+ ```ruby
136
+ bootstrap_icon(class: "my_awesome_class", name: 'glass')
137
+ # => '<i class="icon-glass my_awesome_class"></i>'
138
+ ```
139
+
140
+ ### Buttons
141
+
142
+ ```ruby
143
+ bootstrap_button("Button Text", "#")
144
+ # => '<a class="btn" href="#">Button Text</a>'
145
+ ```
146
+
147
+ ### Link_to, link_to_if, link_to_unless
148
+
149
+ They are a shortcut to bootstrap_button with bootstrap_class_prefix => nil .
150
+ In this way they are rendered as normal bootstrap_button, without being styled.
151
+
152
+ ```ruby
153
+ bootstrap_link_to 'Search', "#", type: 'primary', icon_name: 'search'
154
+ # => '<a href="#"><i class="icon-search"></i> Search</a>'
155
+ ```
156
+
157
+ ```ruby
158
+ bootstrap_link_to_if condition, 'Search', "#", type: 'primary', icon_name: 'search' { nil }
159
+ # => '<a href="#"><i class="icon-search"></i> Search</a>'
160
+ ```
161
+
162
+ ```ruby
163
+ bootstrap_link_to_unless !condition, 'Search', "#", type: 'primary', icon_name: 'search' { nil }
164
+ # => '<a href="#"><i class="icon-search"></i> Search</a>'
165
+ ```
166
+
167
+ ### Dropdown Buttons
168
+
169
+ ```ruby
170
+ bootstrap_button_dropdown do |b|
171
+ b.bootstrap_button "Button Title", "#"
172
+ b.bootstrap_link_to "First Dropdown Item", item_path(@item)
173
+ b.link_to "Second Dropdown Item", @item2
174
+ end
175
+ # => '<div class="btn-group">
176
+ # <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
177
+ # Button Title
178
+ # <span class="caret"></span>
179
+ # </a>
180
+ # <ul class="dropdown-menu">
181
+ # <!-- dropdown menu links -->
182
+ # </ul>
183
+ # </div>'
184
+ ```
185
+
186
+ ### Navigation lists
187
+
188
+ ### Basic tabs example
189
+
190
+ ```ruby
191
+ bootstrap_navigation do |nav|
192
+ nav.link_to "Nav1", "/link1", :active_nav => true
193
+ nav.link_to "Nav2", "/link2"
194
+ end
195
+ # => '<ul class="nav nav-tabs">
196
+ # <li class="active">
197
+ # <a href="/link1">Nav1</a>
198
+ # </li>
199
+ # <li>
200
+ # <a href="/link2">Nav2</a>
201
+ # </li>
202
+ # </ul>'
203
+ ```
204
+
205
+ ### Basic pills example
206
+
207
+ ```ruby
208
+ bootstrap_navigation(:type => "pills") do |nav|
209
+ nav.link_to "Nav1", "/link1"
210
+ nav.link_to "Nav2", "/link2", :active_nav => true
211
+ end
212
+ # => '<ul class="nav nav-pills">
213
+ # <li>
214
+ # <a href="/link1">Nav1</a>
215
+ # </li>
216
+ # <li class="active">
217
+ # <a href="/link2">Nav2</a>
218
+ # </li>
219
+ # </ul>'
220
+ ```
221
+
222
+ ### Stacked tabs example
223
+
224
+ ```ruby
225
+ bootstrap_navigation(:type => "tabs", :stacked => true) do |nav|
226
+ nav.link_to "Nav1", "/link1", :active_nav => true
227
+ nav.link_to "Nav2", "/link2"
228
+ end
229
+ # => '<ul class="nav nav-tabs nav-stacked">
230
+ # <li class="active">
231
+ # <a href="/link1">Nav1</a>
232
+ # </li>
233
+ # <li>
234
+ # <a href="/link2">Nav2</a>
235
+ # </li>
236
+ # </ul>'
237
+ ```
238
+
239
+ ### Stacked pills example
240
+
241
+ ```ruby
242
+ bootstrap_navigation(:type => "pills", :stacked => true) do |nav|
243
+ nav.link_to "Nav1", "/link1"
244
+ nav.link_to "Nav2", "/link2", :active_nav => true
245
+ end
246
+ # => '<ul class="nav nav-pills nav-stacked">
247
+ # <li>
248
+ # <a href="/link1">Nav1</a>
249
+ # </li>
250
+ # <li class="active">
251
+ # <a href="/link2">Nav2</a>
252
+ # </li>
253
+ # </ul>'
254
+ ```
255
+
256
+ ### Modal popup example
257
+
258
+ ```ruby
259
+ bootstrap_modal(id: "a_dom_id", fade: true, title: "Modal title!") do |modal|
260
+ modal.body do |c|
261
+ c.render partial: 'body'
262
+ end
263
+ modal.footer do |c|
264
+ c.bootstrap_button "Close", "#", type: 'danger', html_options: { data: { dismiss: "modal" } }
265
+ c.bootstrap_button "Accept", accept_request_path(@request),
266
+ icon_name: 'ok', type: 'success',
267
+ html_options: { data: { dismiss: "modal" }, method: :put }
268
+ end
269
+ end
270
+ # => '<div class="modal fade" id="a_dom_id">
271
+ # <div class="modal-header">
272
+ # <a class="close" data-dismiss="modal">&times</a>
273
+ # <h3>Modal title!</h3>
274
+ # </div>
275
+ # <div class="modal-body">
276
+ # <div>partial content</div>
277
+ # </div>
278
+ # <div class="modal-footer">
279
+ # <a href="#" data-dismiss="modal" class=" btn btn-danger">Close</a>
280
+ # <a method="put" href="/request/1/accept" data-dismiss="modal" class=" btn btn-success"><i class=" icon icon-ok icon-white"></i> Accept</a>
281
+ # </div>
282
+ # </div>'
283
+ ```
284
+
285
+ Plugins
286
+ ---
287
+
288
+ ### For [SimpleNavigation](https://github.com/andi/simple-navigation)
289
+
290
+ If you are using `simple-navigation` gem you can use the navigation renderer like this:
291
+
292
+ In your initializer:
293
+
294
+ ```ruby
295
+ SimpleNavigation.register_renderer :bootstrap_topbar_list => SimpleNavigation::Renderer::BootstrapTopbarList
296
+ ```
297
+
298
+ ```ruby
299
+ render_navigation(level: 1..2, renderer: :bootstrap_topbar_list, expand_all: true)
300
+ ```
301
+
302
+ Contributing
303
+ ---
304
+
305
+ In the spirit of free software, everyone is encouraged to help improve this project.
306
+
307
+ Here are some ways you can contribute:
308
+
309
+ * by using alpha, beta, and prerelease versions
310
+ * by reporting bugs
311
+ * by suggesting new features
312
+ * by writing or editing documentation
313
+ * by writing specifications
314
+ * by writing code (no patch is too small: fix typos, add comments, clean up inconsistent whitespace)
315
+ * by writing tests
316
+ * by refactoring code
317
+ * by closing [issues](https://github.com/mcanato/shoehorn/issues)
318
+ * by reviewing patches
319
+
320
+ Submitting an Issue
321
+ ---
322
+
323
+ We use the [GitHub issue tracker](https://github.com/mcanato/shoehorn/issues) to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. You can indicate support for an existing issue by voting it up. When submitting a bug report, please include a [gist](https://gist.github.com/) that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and operating system. Ideally, a bug report should include a pull request with failing specs.
324
+
325
+ Submitting a Pull Request
326
+ ---
327
+
328
+ 1. Fork the project.
329
+ 2. Create a topic branch.
330
+ 3. Implement your feature or bug fix.
331
+ 4. Add documentation for your feature or bug fix.
332
+ 5. Run `bundle exec rake yard`. If your changes are not 100% documented, go back to step 4.
333
+ 6. Add specs for your feature or bug fix.
334
+ 7. Run `bundle exec rake spec`. If your changes are not 100% covered, go back to step 6.
335
+ 8. Commit and push your changes.
336
+ 9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ require 'rake/testtask'
5
+ require 'yard'
6
+ require 'yard/rake/yardoc_task'
7
+
8
+ task :default => :spec
9
+
10
+ desc 'Test the plugin.'
11
+ RSpec::Core::RakeTask.new('spec') do |t|
12
+ t.pattern = FileList['spec/**/*_spec.rb']
13
+ end
14
+
15
+ desc 'Generate docs'
16
+ YARD::Rake::YardocTask.new do |t|
17
+ t.files = ['lib/**/*.rb']
18
+ #t.options = ['--plugin', 'yard-tomdoc']
19
+ end
20
+
21
+ if RUBY_VERSION =~ /^1\.9/
22
+ desc "Code coverage detail"
23
+ task :simplecov do
24
+ ENV['COVERAGE'] = "true"
25
+ Rake::Task['spec'].execute
26
+ end
27
+ else
28
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+ end
data/lib/shoehorn.rb ADDED
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
2
+
3
+ module Shoehorn
4
+ require "shoehorn/version"
5
+
6
+ require "shoehorn/helper_collection"
7
+ require "shoehorn/helper_collection_set"
8
+
9
+ autoload :Helpers, "shoehorn/helpers"
10
+ autoload :Components, "shoehorn/components"
11
+
12
+ require "shoehorn/engine" if defined?(::Rails)
13
+ require "shoehorn/plugins"
14
+ end
15
+
@@ -0,0 +1,17 @@
1
+ module Shoehorn
2
+ module Components
3
+ autoload :Base, 'shoehorn/components/base'
4
+ autoload :Badge, 'shoehorn/components/badge'
5
+ autoload :Alert, 'shoehorn/components/alert'
6
+ autoload :Label, 'shoehorn/components/label'
7
+ autoload :Icon, 'shoehorn/components/icon'
8
+ #autoload :Form, 'shoehorn/components/form'
9
+ #autoload :FormBuilder, 'shoehorn/components/form_builder'
10
+ autoload :Button, 'shoehorn/components/button'
11
+ autoload :ButtonDropdown, 'shoehorn/components/button_dropdown'
12
+ autoload :Navigation, 'shoehorn/components/navigation'
13
+ autoload :Modal, 'shoehorn/components/modal'
14
+ autoload :ProgressBar, 'shoehorn/components/progress_bar'
15
+ end
16
+ end
17
+
@@ -0,0 +1,69 @@
1
+ module Shoehorn::Components
2
+ class Alert < Base
3
+ attr_reader :message
4
+
5
+ def initialize(message, options = {})
6
+ super
7
+ @message = message
8
+ end
9
+
10
+ def to_s
11
+ output_buffer << content_tag(:div, build_div_options) do
12
+ html = ""
13
+ html << build_close_tag.html_safe if options[:close]
14
+ html << build_heading_tag.html_safe if options[:heading]
15
+ html << message
16
+ html.html_safe
17
+ end.html_safe
18
+ super
19
+ end
20
+
21
+ private
22
+ def default_options
23
+ {
24
+ :class => "alert",
25
+ :block => false,
26
+ :close => true,
27
+ :heading => nil,
28
+ :dismiss => true,
29
+ :type => nil,
30
+ :html_options => {}
31
+ }
32
+ end
33
+
34
+ def build_close_tag
35
+ content_tag(:a, "&times;".html_safe, close_tag_options)
36
+ end
37
+
38
+ def build_heading_tag
39
+ options[:block] ? build_block_heading : build_inline_heading
40
+ end
41
+
42
+ def build_block_heading
43
+ content_tag(:h4, options[:heading], :class => 'alert-heading')
44
+ end
45
+
46
+ def build_inline_heading
47
+ content_tag(:strong, options[:heading])
48
+ end
49
+
50
+ def close_tag_options
51
+ opts = { :class => "close" }
52
+ opts["data-dismiss"] = "alert" if options[:dismiss]
53
+ opts
54
+ end
55
+
56
+ def build_div_options
57
+ opts = { :class => build_class }
58
+ opts.reverse_merge(options[:html_options])
59
+ end
60
+
61
+ def build_class
62
+ classes = %w(alert)
63
+ classes << "alert-block" if options[:block]
64
+ classes << "alert-#{options[:type]}" if options[:type]
65
+ classes.join(" ")
66
+ end
67
+ end
68
+ end
69
+