card-mod-bootstrap 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate_core_cards/20170719163733_update_bootswatch_themes_to_4_beta.rb +1 -2
  3. data/db/migrate_core_cards/20170726111053_add_bootstrap_mixins.rb +2 -2
  4. data/db/migrate_core_cards/20170726145012_select2.rb +2 -2
  5. data/db/migrate_core_cards/20180423160231_migrate_customized_bootstrap_skin.rb +1 -0
  6. data/db/migrate_core_cards/20180423170283_add_type_bootswatch_skin.rb +1 -0
  7. data/db/migrate_core_cards/20180425174433_delete_deprecated_skin_cards.rb +1 -0
  8. data/db/migrate_core_cards/20181129140917_fix_skin_images.rb +0 -1
  9. data/db/migrate_core_cards/data/20181108181219_migrate_classic_skins_to_bootstrap.rb +1 -0
  10. data/db/migrate_core_cards/lib/skin.rb +1 -1
  11. data/lib/card/bootstrap.rb +17 -0
  12. data/lib/card/bootstrap/basic_tags.rb +26 -0
  13. data/lib/card/bootstrap/component.rb +110 -0
  14. data/lib/card/bootstrap/component/carousel.rb +78 -0
  15. data/lib/card/bootstrap/component/form.rb +67 -0
  16. data/lib/card/bootstrap/component/horizontal_form.rb +65 -0
  17. data/lib/card/bootstrap/component/layout.rb +107 -0
  18. data/lib/card/bootstrap/component/panel.rb +11 -0
  19. data/lib/card/bootstrap/component_klass.rb +37 -0
  20. data/lib/card/bootstrap/component_loader.rb +30 -0
  21. data/lib/card/bootstrap/content.rb +42 -0
  22. data/lib/card/bootstrap/delegate.rb +18 -0
  23. data/lib/card/bootstrap/old_component.rb +108 -0
  24. data/lib/card/bootstrap/tag_method.rb +56 -0
  25. data/lib/card/bootstrapper.rb +17 -0
  26. data/lib/card/tab.rb +8 -1
  27. data/set/abstract/bootstrap_code_file.rb +0 -1
  28. data/set/abstract/bootswatch_theme.rb +1 -0
  29. data/set/abstract/bs_badge/tab_badge.haml +1 -1
  30. data/set/all/bootstrap/dropdown.rb +12 -4
  31. data/set/all/bootstrap/helper.rb +18 -11
  32. data/set/all/bootstrap/icon.rb +3 -1
  33. data/set/all/bootstrap/table.rb +1 -0
  34. data/set/all/bootstrap/wrapper.rb +2 -4
  35. data/set/self/bootstrap_core.rb +7 -8
  36. data/set/type/customized_bootswatch_skin.rb +11 -7
  37. data/set/type_plus_right/customized_bootswatch_skin/colors.rb +3 -2
  38. metadata +28 -27
  39. data/lib/bootstrap.rb +0 -16
  40. data/lib/bootstrap/basic_tags.rb +0 -26
  41. data/lib/bootstrap/component.rb +0 -139
  42. data/lib/bootstrap/component/carousel.rb +0 -68
  43. data/lib/bootstrap/component/form.rb +0 -65
  44. data/lib/bootstrap/component/horizontal_form.rb +0 -63
  45. data/lib/bootstrap/component/layout.rb +0 -95
  46. data/lib/bootstrap/component/panel.rb +0 -9
  47. data/lib/bootstrap/component_loader.rb +0 -28
  48. data/lib/bootstrap/content.rb +0 -40
  49. data/lib/bootstrap/delegate.rb +0 -16
  50. data/lib/bootstrap/old_component.rb +0 -103
  51. data/lib/bootstrap/tag_method.rb +0 -54
  52. data/lib/bootstrapper.rb +0 -16
@@ -0,0 +1,107 @@
1
+ class Card
2
+ class Bootstrap
3
+ class Component
4
+ # generate bootstrap column layout
5
+ # @example
6
+ # layout container: true, fluid: true, class: "hidden" do
7
+ # row 6, 6, class: "unicorn" do
8
+ # column "horn",
9
+ # column "rainbow", class: "colorful"
10
+ # end
11
+ # end
12
+ # @example
13
+ # layout do
14
+ # row 3, 3, 4, 2, class: "unicorn" do
15
+ # [ "horn", "body", "tail", "rainbow"]
16
+ # end
17
+ # add_html "<span> some extra html</span>"
18
+ # row 6, 6, ["unicorn", "rainbow"], class: "horn"
19
+ # end
20
+ class Layout < OldComponent
21
+ def render
22
+ @rendered = begin
23
+ render_content
24
+ @content[-1]
25
+ end
26
+ end
27
+
28
+ def render_content
29
+ content = instance_exec(*@args, &@build_block)
30
+ add_content content
31
+ opts = @args.first
32
+ return unless opts&.delete(:container)
33
+
34
+ content = @content.pop
35
+ @content = ["".html_safe]
36
+ container content, opts
37
+ end
38
+
39
+ add_div_method :container, nil do |opts, _extra_args|
40
+ prepend_class opts, opts.delete(:fluid) ? "container-fluid" : "container"
41
+ opts
42
+ end
43
+
44
+ # @param args column widths, column content and html attributes
45
+ # @example
46
+ # row 6, 6, ["col one", "col two"], class: "count", id: "count"
47
+ # @example
48
+ # row md: 12, xs: 8, "single column content"
49
+ # @example
50
+ # row md: [1, 11], xs: [2, 10] do
51
+ # col "A"
52
+ # col "B"
53
+ # end
54
+ add_div_method :row, "row", content_processor: :column do |opts, extra_args|
55
+ cols_content = extra_args.pop if extra_args.last.is_a? Array
56
+ [opts, col_widths(extra_args, opts), cols_content].compact
57
+ end
58
+
59
+ # default column width type is for medium devices (col-md-)
60
+ add_div_method :column, nil do |opts, _extra_args|
61
+ @child_args.last.each do |medium, size|
62
+ if medium == :xs
63
+ prepend_class opts, "col-#{size.shift}"
64
+ else
65
+ prepend_class opts, "col-#{medium}-#{size.shift}"
66
+ end
67
+ end
68
+ opts
69
+ end
70
+
71
+ alias_method :col, :column
72
+
73
+ private
74
+
75
+ def standardize_row_args args
76
+ opts = args.last.is_a?(Hash) ? args.pop : {}
77
+ cols = (args.last.is_a?(Array) || args.last.is_a?(String)) &&
78
+ Array.wrap(args.pop)
79
+ [cols, opts, col_widths(args, opts)]
80
+ end
81
+
82
+ def col_widths args, opts
83
+ opts = args.pop if args.one? && args.last.is_a?(Hash)
84
+ if args.present?
85
+ col_widths_from_args args
86
+ else
87
+ col_widths_from_opts opts
88
+ end
89
+ end
90
+
91
+ def col_widths_from_args args
92
+ raise Error, "bad argument" unless args.all? { |a| a.is_a? Integer }
93
+
94
+ { md: Array.wrap(args) }
95
+ end
96
+
97
+ def col_widths_from_opts opts
98
+ %i[lg xs sm md].each_with_object({}) do |k, cols_w|
99
+ next unless (widths = opts.delete(k))
100
+
101
+ cols_w[k] = Array.wrap widths
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,11 @@
1
+ class Card
2
+ class Bootstrap
3
+ class Component
4
+ class Panel < OldComponent
5
+ def_div_method :panel, "card"
6
+ def_div_method :heading, "card-header"
7
+ def_div_method :body, "card-body"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ class Card
2
+ class Bootstrap
3
+ # class methods for Bootstrap::Component
4
+ module ComponentKlass
5
+ def render format, *args, &block
6
+ new(format, *args, &block).render
7
+ end
8
+
9
+ # Like def_tag_method but always generates a div tag
10
+ # The tag option is not available
11
+ def def_div_method name, html_class, opts={}, &tag_block
12
+ def_tag_method name, html_class, opts.merge(tag: :div), &tag_block
13
+ end
14
+
15
+ # Defines a method that generates a html tag
16
+ # @param method_name [Symbol, String] the name of the method. If no :tag option
17
+ # in tag_opts is defined then the name is also the name of the tag that the
18
+ # method generates
19
+ # @param html_class [String] a html class that is added to tag. Use nil if you
20
+ # don't want a html_class
21
+ # @param tag_opts [Hash] additional argument that will be added to the tag
22
+ # @option tag_opts [Symbol, String] tag the name of the tag
23
+ # @example
24
+ # def_tag_method :link, "known-link", tag: :a, id: "uniq-link"
25
+ # link # => <a class="known-link" id="uniq-link"></a>
26
+ def def_tag_method method_name, html_class, tag_opts={}, &tag_opts_block
27
+ tag = tag_opts.delete(:tag) || method_name
28
+ define_method method_name do |*args, &content_block|
29
+ @html.tag! tag,
30
+ tag_method_opts(args, html_class, tag_opts, &tag_opts_block) do
31
+ instance_exec(&content_block)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ class Card
2
+ class Bootstrap
3
+ module ComponentLoader
4
+ def load_components
5
+ components.each do |component|
6
+ require_relative "component/#{component}"
7
+ include_component component
8
+ end
9
+ end
10
+
11
+ def include_component component
12
+ component_class = to_const component.camelcase
13
+ define_method component do |*args, &block|
14
+ component_class.render self, *args, &block
15
+ end
16
+ end
17
+
18
+ def components
19
+ path = File.expand_path "component/*.rb", __dir__
20
+ Dir.glob(path).map do |file|
21
+ File.basename file, ".rb"
22
+ end
23
+ end
24
+
25
+ def to_const name
26
+ self.class.const_get "::Card::Bootstrap::Component::#{name.camelcase}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ class Card
2
+ class Bootstrap
3
+ # shared methods for OldComponent and TagMethod
4
+ module Content
5
+ private
6
+
7
+ def process_collected_content tag_name, opts
8
+ collected_content = @content.pop
9
+ tag_name = opts.delete(:tag) if tag_name == :yield
10
+ add_content content_tag(tag_name, collected_content, opts, false)
11
+ end
12
+
13
+ def process_content &content_block
14
+ content, opts = yield
15
+ wrappers = @wrap.pop
16
+ if wrappers.present?
17
+ process_wrappers wrappers, content, &content_block
18
+ else
19
+ add_content content
20
+ end
21
+ opts
22
+ end
23
+
24
+ def process_append
25
+ @append.pop.each do |block|
26
+ add_content instance_exec(&block)
27
+ end
28
+ end
29
+
30
+ def process_wrappers wrappers, content, &content_block
31
+ while wrappers.present?
32
+ wrapper = wrappers.shift
33
+ if wrapper.is_a? Symbol
34
+ send wrapper, &content_block
35
+ else
36
+ instance_exec content, &wrappers.shift
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ class Card
2
+ class Bootstrap
3
+ module Delegate
4
+ def method_missing method_name, *args, &block
5
+ # return super unless @context.respond_to? method_name
6
+ if block_given?
7
+ @context.send(method_name, *args, &block)
8
+ else
9
+ @context.send(method_name, *args)
10
+ end
11
+ end
12
+
13
+ def respond_to_missing? method_name, _include_private=false
14
+ @context.respond_to? method_name
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,108 @@
1
+ class Card
2
+ class Bootstrap
3
+ # not-yet-obviated component handling
4
+ class OldComponent < Component
5
+ include Content
6
+
7
+ def initialize context, *args, &block
8
+ @context = context
9
+ @content = ["".html_safe]
10
+ @args = args
11
+ @child_args = []
12
+ @append = []
13
+ @wrap = []
14
+ @build_block = block
15
+ end
16
+
17
+ class << self
18
+ def render format, *args, &block
19
+ new(format, *args, &block).render
20
+ end
21
+
22
+ # Like add_tag_method but always generates a div tag
23
+ # The tag option is not available
24
+ def add_div_method name, html_class, opts={}, &tag_block
25
+ add_tag_method name, html_class, opts.merge(tag: :div), &tag_block
26
+ end
27
+
28
+ # Defines a method that generates a html tag
29
+ # @param name [Symbol, String] the name of the method. If no :tag option in
30
+ # tag_opts is defined then the name is also the name of the tag that the method
31
+ # generates
32
+ # @param html_class [String] a html class that is added to tag. Use nil if you
33
+ # don't want a html_class
34
+ # @param tag_opts [Hash] additional argument that will be added to the tag
35
+ # @option tag_opts [Symbol, String] tag the name of the tag
36
+ # @example
37
+ # add_tag_method :link, "known-link", tag: :a, id: "uniq-link"
38
+ # link # => <a class="known-link" id="uniq-link"></a>
39
+ def add_tag_method name, html_class, tag_opts={}, &tag_block
40
+ define_method name do |*args, &block|
41
+ process_tag tag_opts[:tag] || name do
42
+ content, opts, new_child_args = standardize_args args, &tag_block
43
+ add_classes opts, html_class, tag_opts.delete(:optional_classes)
44
+ if (attributes = tag_opts.delete(:attributes))
45
+ opts.merge! attributes
46
+ end
47
+
48
+ content = with_child_args new_child_args do
49
+ generate_content content,
50
+ tag_opts[:content_processor],
51
+ &block
52
+ end
53
+
54
+ [content, opts]
55
+ end
56
+ end
57
+ end
58
+
59
+ alias_method :def_div_method, :add_div_method
60
+ alias_method :def_tag_method, :add_tag_method
61
+ end
62
+
63
+ def render
64
+ @rendered = begin
65
+ render_content
66
+ @content[-1]
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def process_tag tag_name, &content_block
73
+ @content.push "".html_safe
74
+ @append << []
75
+ @wrap << []
76
+
77
+ opts = process_content(&content_block)
78
+ process_collected_content tag_name, opts
79
+ process_append
80
+ ""
81
+ end
82
+
83
+ # include BasicTags
84
+ def html content
85
+ add_content String(content).html_safe
86
+ ""
87
+ end
88
+
89
+ add_div_method :div, nil do |opts, extra_args|
90
+ prepend_class opts, extra_args.first if extra_args.present?
91
+ opts
92
+ end
93
+
94
+ add_div_method :span, nil do |opts, extra_args|
95
+ prepend_class opts, extra_args.first if extra_args.present?
96
+ opts
97
+ end
98
+
99
+ add_tag_method :tag, nil, tag: :yield do |opts, extra_args|
100
+ prepend_class opts, extra_args[1] if extra_args[1].present?
101
+ opts[:tag] = extra_args[0]
102
+ opts
103
+ end
104
+
105
+ include Delegate
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,56 @@
1
+ class Card
2
+ class Bootstrap
3
+ # support html tag generation
4
+ class TagMethod
5
+ include Content
6
+
7
+ def initialize component, name, html_class, tag_opts={}, &tag_block
8
+ @component = component
9
+ @name = name
10
+ @html_class = html_class
11
+ @tag_opts = tag_opts
12
+ @tag_block = tag_block
13
+ @append = []
14
+ @wrap = []
15
+ @xm = Builder::XmlMarkup.new
16
+ end
17
+
18
+ def call *_args, &content_block
19
+ component.content.push "".html_safe
20
+
21
+ opts = process_content(&content_block)
22
+ process_collected_content tag_name, opts
23
+ process_append
24
+ ""
25
+ end
26
+
27
+ def method_missing method, *args, &block
28
+ return super unless respond_to_missing? method
29
+
30
+ @component.send method, *args, &block
31
+ end
32
+
33
+ def respond_to_missing? method, _include_private=false
34
+ @component.respond_to? method
35
+ end
36
+
37
+ def prepend &block
38
+ tmp = @content.pop
39
+ instance_exec(&block)
40
+ @content << tmp
41
+ end
42
+
43
+ def wrap &block
44
+ instance_exec(&block)
45
+ end
46
+
47
+ def append &block
48
+ @append[-1] << block
49
+ end
50
+
51
+ def wrapInner tag=nil, &block
52
+ @wrap[-1] << (block_given? ? block : tag)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ class Card
2
+ module Bootstrapper
3
+ extend Bootstrap::ComponentLoader
4
+
5
+ def bootstrap
6
+ @bootstrap ||= Bootstrap.new(self)
7
+ end
8
+
9
+ def bs *args, &block
10
+ bootstrap.render(*args, &block)
11
+ end
12
+
13
+ components.each do |component|
14
+ delegate component, to: :bootstrap, prefix: :bs
15
+ end
16
+ end
17
+ end
data/lib/card/tab.rb CHANGED
@@ -5,11 +5,18 @@ class Card
5
5
  class << self
6
6
  def tab_objects format, tab_hash, active_name, klass=nil
7
7
  klass ||= Card::Tab
8
- active_name ||= tab_hash.keys.first
8
+ active_name = active active_name, tab_hash.keys
9
9
  tab_hash.map do |name, config|
10
10
  klass.new format, name, active_name, config
11
11
  end
12
12
  end
13
+
14
+ private
15
+
16
+ def active requested, keys
17
+ r = requested.to_name
18
+ r && keys.find { |k| k.to_name == r } || keys.first
19
+ end
13
20
  end
14
21
 
15
22
  delegate :add_class, :wrap_with, :unique_id, :link_to, to: :format