twitter-bootstrap-components-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +44 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/config/twitter_bootstrap_components_rails_manifest.js +2 -0
  6. data/app/assets/javascripts/twitter/bootstrap/components/rails/application.js +13 -0
  7. data/app/assets/stylesheets/twitter/bootstrap/components/rails/application.css +15 -0
  8. data/app/components/twitter/bootstrap/components/v3/alert.rb +34 -0
  9. data/app/components/twitter/bootstrap/components/v3/badge.rb +32 -0
  10. data/app/components/twitter/bootstrap/components/v3/base.rb +30 -0
  11. data/app/components/twitter/bootstrap/components/v3/button_group.rb +49 -0
  12. data/app/components/twitter/bootstrap/components/v3/media_object.rb +56 -0
  13. data/app/components/twitter/bootstrap/components/v3/thumbnail.rb +40 -0
  14. data/app/components/twitter/bootstrap/components/v4/alert.rb +39 -0
  15. data/app/components/twitter/bootstrap/components/v4/badge.rb +34 -0
  16. data/app/components/twitter/bootstrap/components/v4/base.rb +34 -0
  17. data/app/components/twitter/bootstrap/components/v4/button.rb +85 -0
  18. data/app/components/twitter/bootstrap/components/v4/button_group.rb +30 -0
  19. data/app/components/twitter/bootstrap/components/v4/card.rb +64 -0
  20. data/app/components/twitter/bootstrap/components/v4/card/block.rb +17 -0
  21. data/app/components/twitter/bootstrap/components/v4/card/blockquote.rb +17 -0
  22. data/app/components/twitter/bootstrap/components/v4/card/footer.rb +22 -0
  23. data/app/components/twitter/bootstrap/components/v4/card/header.rb +17 -0
  24. data/app/components/twitter/bootstrap/components/v4/flash.rb +33 -0
  25. data/app/components/twitter/bootstrap/components/v4/navbar_brand.rb +31 -0
  26. data/app/controllers/twitter/bootstrap/components/rails/application_controller.rb +11 -0
  27. data/app/form_builders/twitter/bootstrap/components/rails/v4/default_form_builder.rb +15 -0
  28. data/app/helpers/twitter/bootstrap/components/rails/v3/components_helper.rb +30 -0
  29. data/app/helpers/twitter/bootstrap/components/rails/v4/components_helper.rb +128 -0
  30. data/app/mailers/twitter/bootstrap/components/rails/application_mailer.rb +12 -0
  31. data/app/models/twitter/bootstrap/components/rails/application_record.rb +11 -0
  32. data/app/views/layouts/twitter/bootstrap/components/rails/application.html.erb +14 -0
  33. data/app/views/twitter/bootstrap/components/v3/_alert.html.haml +5 -0
  34. data/app/views/twitter/bootstrap/components/v3/_badge.html.haml +2 -0
  35. data/app/views/twitter/bootstrap/components/v3/_button_group.html.haml +2 -0
  36. data/app/views/twitter/bootstrap/components/v3/_media_object.html.haml +19 -0
  37. data/app/views/twitter/bootstrap/components/v3/_thumbnail.html.haml +18 -0
  38. data/app/views/twitter/bootstrap/components/v4/_alert.html.haml +5 -0
  39. data/app/views/twitter/bootstrap/components/v4/_badge.html.haml +2 -0
  40. data/app/views/twitter/bootstrap/components/v4/_button.haml +10 -0
  41. data/app/views/twitter/bootstrap/components/v4/_button_group.haml +2 -0
  42. data/app/views/twitter/bootstrap/components/v4/_card.html.haml +6 -0
  43. data/app/views/twitter/bootstrap/components/v4/_card_kitchen_sink.html.haml +4 -0
  44. data/app/views/twitter/bootstrap/components/v4/_card_list_group.html.haml +2 -0
  45. data/app/views/twitter/bootstrap/components/v4/_flash.html.haml +3 -0
  46. data/app/views/twitter/bootstrap/components/v4/_navbar_brand.html.haml +2 -0
  47. data/app/views/twitter/bootstrap/components/v4/card/_block.html.haml +2 -0
  48. data/app/views/twitter/bootstrap/components/v4/card/_blockquote.html.haml +2 -0
  49. data/app/views/twitter/bootstrap/components/v4/card/_footer.html.haml +2 -0
  50. data/app/views/twitter/bootstrap/components/v4/card/_header.html.haml +2 -0
  51. data/config/routes.rb +2 -0
  52. data/lib/tasks/twitter/bootstrap/components/rails_tasks.rake +4 -0
  53. data/lib/twitter/bootstrap/components/rails.rb +14 -0
  54. data/lib/twitter/bootstrap/components/rails/engine.rb +11 -0
  55. data/lib/twitter/bootstrap/components/rails/version.rb +9 -0
  56. data/lib/twitter_bootstrap_components_rails.rb +1 -0
  57. metadata +211 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 944fea1ebbc771146073c0158384ada4d0145eb8
4
+ data.tar.gz: 39b1912b49d393ef66a3c914015f58fd1f9e3345
5
+ SHA512:
6
+ metadata.gz: f7f9170999f4632ac844d14ba3338acb82b4a50739d7c00a410b64e4b45929c4704e00b493888f4c11dcc10977c38501b3a24e71bf3bc3d5e267583eedd2bb52
7
+ data.tar.gz: 92f82c9dc717fbfc87ac3634e77fc3309d2988598b674fbfbeb76c580ca165fbfef2009ee884cf33b99e37da3f338c033b66e6409d18c5b4cf5df36547cdc299
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Roberto Vasquez Angel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Twitter::Bootstrap::Components::Rails
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ Add the helper to your application controller.
6
+
7
+ Bootstrap v3
8
+
9
+ ```ruby
10
+ class ApplicationController < ActionController::Base
11
+ helper Twitter::Bootstrap::Components::Rails::V3::ComponentsHelper
12
+ end
13
+ ```
14
+
15
+ Bootstrap v4
16
+
17
+ ```ruby
18
+ class ApplicationController < ActionController::Base
19
+ helper Twitter::Bootstrap::Components::Rails::V4::ComponentsHelper
20
+ end
21
+ ```
22
+
23
+ ## Installation
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'twitter-bootstrap-components-rails'
28
+ ```
29
+
30
+ And then execute:
31
+ ```bash
32
+ $ bundle
33
+ ```
34
+
35
+ Or install it yourself as:
36
+ ```bash
37
+ $ gem install twitter-bootstrap-components-rails
38
+ ```
39
+
40
+ ## Contributing
41
+ Contribution directions go here.
42
+
43
+ ## License
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Twitter::Bootstrap::Components::Rails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/twitter/bootstrap/components/rails .js
2
+ //= link_directory ../stylesheets/twitter/bootstrap/components/rails .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,34 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V3
5
+ class Alert < Base
6
+ private
7
+
8
+ def view_locals
9
+ {
10
+ block_output: @block_output,
11
+ context: context,
12
+ dismissible: dismissible?,
13
+ div_alert_classes: div_alert_classes
14
+ }
15
+ end
16
+
17
+ def dismissible?
18
+ !!@options[:dismissible]
19
+ end
20
+
21
+ def div_alert_classes
22
+ classes = ["alert", "alert-#{context}"]
23
+ classes << ["alert-dismissible"] if @options[:dismissible]
24
+ classes
25
+ end
26
+
27
+ def context
28
+ @options[:context]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V3
5
+ class Badge < Base
6
+
7
+ private
8
+
9
+ def view_locals
10
+ {
11
+ block_output: @block_output,
12
+ context: context,
13
+ span_badge_classes: span_badge_classes
14
+ }
15
+ end
16
+
17
+ def pill?
18
+ !!@options[:pill]
19
+ end
20
+
21
+ def span_badge_classes
22
+ ["badge", "badge-#{context}"]
23
+ end
24
+
25
+ def context
26
+ @options[:context]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V3
5
+ class Base
6
+ def initialize(view, options = {}, &block)
7
+ @view = view
8
+ @options = options
9
+ @block = block
10
+ @view_locals = {}
11
+ end
12
+
13
+ def perform
14
+ @block_output = block_output
15
+ @view.render partial: self.class.name.underscore, locals: view_locals
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :view_locals
21
+
22
+ def block_output
23
+ return unless @block.present?
24
+ @view.capture { @block.call(self) }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V3
5
+ class ButtonGroup < Base
6
+ SIZE_MAP = {
7
+ default: nil,
8
+ extra_small: :xs,
9
+ small: :sm,
10
+ large: :lg
11
+ }.freeze
12
+
13
+ private
14
+
15
+ def view_locals
16
+ {
17
+ block_output: @block_output,
18
+ div_css_classes: div_css_classes
19
+ }
20
+ end
21
+
22
+ def div_css_classes
23
+ [group_css_class, size_css_class, justified_css_class, drop_up_css_class].compact
24
+ end
25
+
26
+ def size
27
+ @options[:size] || :default
28
+ end
29
+
30
+ def size_css_class
31
+ SIZE_MAP[size]
32
+ end
33
+
34
+ def group_css_class
35
+ @options[:vertical] ? 'btn-group-vertical' : 'btn-group'
36
+ end
37
+
38
+ def justified_css_class
39
+ @options[:justified] ? 'btn-group-justified' : nil
40
+ end
41
+
42
+ def drop_up_css_class
43
+ @options[:drop_up] ? 'dropup' : nil
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,56 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V3
5
+ class MediaObject < Base
6
+ DEFAULT_IMAGE_SRC = "https://placeholdit.imgix.net/~text?txtsize=16&txt=64x64&w=64&h=64".freeze
7
+
8
+ private
9
+
10
+ def view_locals
11
+ {
12
+ block_output: @block_output,
13
+ context: context,
14
+ div_media_object_classes: div_media_object_classes,
15
+ image_options: image_options,
16
+ link_target: link_target,
17
+ horizontal_alignment: horizontal_alignment
18
+ }
19
+ end
20
+
21
+ def div_media_object_classes
22
+ ["media-#{horizontal_alignment}", "media-#{vertical_alignment}"]
23
+ end
24
+
25
+ def context
26
+ @options[:context]
27
+ end
28
+
29
+ def horizontal_alignment
30
+ @horizontal_alignment = @options[:horizontal_alignment] || :left
31
+ unless [:left, :right].include?(@horizontal_alignment)
32
+ raise "horizontal_alignment must be either :left or :right, but #{@horizontal_alignment} was given."
33
+ end
34
+ @horizontal_alignment
35
+ end
36
+
37
+ def vertical_alignment
38
+ @vertical_alignment = @options[:vertical_alignment] || :top
39
+ unless [:top, :middle, :bottom].include?(@vertical_alignment)
40
+ raise "vertical_alignment must be either :top, :middle or :bottom, but #{@vertical_alignment} was given."
41
+ end
42
+ @vertical_alignment
43
+ end
44
+
45
+ def image_options
46
+ @image_options ||= (@options[:image_options] || {}).reverse_merge!(alt: nil, src: DEFAULT_IMAGE_SRC)
47
+ end
48
+
49
+ def link_target
50
+ @options[:link_target]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,40 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V3
5
+ class Thumbnail < Base
6
+ DEFAULT_IMAGE_SRC = "https://placeholdit.imgix.net/~text?txtsize=16&txt=242x200&w=242&h=200".freeze
7
+ DEFAULT_CONTAINER_CLASSES = "col-xs-6 col-md-3".freeze
8
+
9
+ private
10
+
11
+ def view_locals
12
+ {
13
+ block_output: @block_output,
14
+ context: context,
15
+ container_classes: container_classes,
16
+ image_options: image_options,
17
+ link_options: link_options
18
+ }
19
+ end
20
+
21
+ def context
22
+ @options[:context]
23
+ end
24
+
25
+ def container_classes
26
+ @options[:container_classes] || DEFAULT_CONTAINER_CLASSES
27
+ end
28
+
29
+ def image_options
30
+ (@options[:image_options] || {}).reverse_merge!(alt: nil, src: DEFAULT_IMAGE_SRC)
31
+ end
32
+
33
+ def link_options
34
+ @options[:link_options] || {}
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V4
5
+ class Alert < Base
6
+ private
7
+
8
+ def view_locals
9
+ {
10
+ block_output: @block_output,
11
+ context: context,
12
+ dismissible: dismissible?,
13
+ div_alert_classes: div_alert_classes
14
+ }
15
+ end
16
+
17
+ def dismissible?
18
+ !!@options[:dismissible]
19
+ end
20
+
21
+ def div_alert_classes
22
+ classes = ["alert", "alert-#{context}"]
23
+ classes << ["alert-dismissible", *@options[:dismissible]] if @options[:dismissible].respond_to?(:join)
24
+ classes << additional_css_classes
25
+ classes
26
+ end
27
+
28
+ def context
29
+ @options[:context]
30
+ end
31
+
32
+ def additional_css_classes
33
+ @options[:class]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ module Twitter
2
+ module Bootstrap
3
+ module Components
4
+ module V4
5
+ class Badge < Base
6
+
7
+ private
8
+
9
+ def view_locals
10
+ {
11
+ block_output: @block_output,
12
+ context: context,
13
+ span_badge_classes: span_badge_classes
14
+ }
15
+ end
16
+
17
+ def pill?
18
+ !!@options[:pill]
19
+ end
20
+
21
+ def span_badge_classes
22
+ classes = ["badge", "badge-#{context}"]
23
+ classes << 'badge-pill' if pill?
24
+ classes
25
+ end
26
+
27
+ def context
28
+ @options[:context]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end