card-mod-bootstrap 0.11.7 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
- class Bootstrap
2
- class Component
1
+ class Card
2
+ class Bootstrap
3
3
  # class methods for Bootstrap::Component
4
- module ComponentClass
4
+ module ComponentKlass
5
5
  def render format, *args, &block
6
6
  new(format, *args, &block).render
7
7
  end
@@ -26,7 +26,8 @@ class Bootstrap
26
26
  def def_tag_method method_name, html_class, tag_opts={}, &tag_opts_block
27
27
  tag = tag_opts.delete(:tag) || method_name
28
28
  define_method method_name do |*args, &content_block|
29
- @html.tag! tag, tag_method_opts(args, html_class, tag_opts, &tag_opts_block) do
29
+ @html.tag! tag,
30
+ tag_method_opts(args, html_class, tag_opts, &tag_opts_block) do
30
31
  instance_exec(&content_block)
31
32
  end
32
33
  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
+ class Bootstrap
3
+ include Delegate
4
+ extend ComponentLoader
5
+ load_components
6
+
7
+ attr_reader :context
8
+
9
+ def initialize context=nil
10
+ @context = context
11
+ end
12
+
13
+ def render *args, &block
14
+ instance_exec(*args, &block)
15
+ end
16
+ end
17
+ 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
@@ -96,7 +96,9 @@ format :html do
96
96
  end
97
97
 
98
98
  def font_awesome_icon_tag icon, opts={}
99
- prepend_class opts, "fa fa-#{icon_class(:font_awesome, icon)}"
99
+
100
+ prepend_class opts,
101
+ "fa#{'b' if opts.delete :brand} fa-#{icon_class(:font_awesome, icon)}"
100
102
  wrap_with :i, "", opts
101
103
  end
102
104
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.7
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-08-01 00:00:00.000000000 Z
13
+ date: 2021-07-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,70 +18,70 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.101.7
21
+ version: 1.102.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.101.7
28
+ version: 1.102.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: card-mod-edit
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: 0.11.7
35
+ version: 0.12.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '='
41
41
  - !ruby/object:Gem::Version
42
- version: 0.11.7
42
+ version: 0.12.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: card-mod-bar_and_box
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - '='
48
48
  - !ruby/object:Gem::Version
49
- version: 0.11.7
49
+ version: 0.12.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - '='
55
55
  - !ruby/object:Gem::Version
56
- version: 0.11.7
56
+ version: 0.12.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: card-mod-style
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.11.7
63
+ version: 0.12.0
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.11.7
70
+ version: 0.12.0
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: card-mod-script
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.11.7
77
+ version: 0.12.0
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: 0.11.7
84
+ version: 0.12.0
85
85
  description: ''
86
86
  email:
87
87
  - info@decko.org
@@ -226,21 +226,21 @@ files:
226
226
  - file/yeti_skin_image/image-medium.png
227
227
  - file/yeti_skin_image/image-original.png
228
228
  - file/yeti_skin_image/image-small.png
229
- - lib/bootstrap.rb
230
- - lib/bootstrap/basic_tags.rb
231
- - lib/bootstrap/component.rb
232
- - lib/bootstrap/component/carousel.rb
233
- - lib/bootstrap/component/component_class.rb
234
- - lib/bootstrap/component/form.rb
235
- - lib/bootstrap/component/horizontal_form.rb
236
- - lib/bootstrap/component/layout.rb
237
- - lib/bootstrap/component/panel.rb
238
- - lib/bootstrap/component_loader.rb
239
- - lib/bootstrap/content.rb
240
- - lib/bootstrap/delegate.rb
241
- - lib/bootstrap/old_component.rb
242
- - lib/bootstrap/tag_method.rb
243
- - lib/bootstrapper.rb
229
+ - lib/card/bootstrap.rb
230
+ - lib/card/bootstrap/basic_tags.rb
231
+ - lib/card/bootstrap/component.rb
232
+ - lib/card/bootstrap/component/carousel.rb
233
+ - lib/card/bootstrap/component/form.rb
234
+ - lib/card/bootstrap/component/horizontal_form.rb
235
+ - lib/card/bootstrap/component/layout.rb
236
+ - lib/card/bootstrap/component/panel.rb
237
+ - lib/card/bootstrap/component_klass.rb
238
+ - lib/card/bootstrap/component_loader.rb
239
+ - lib/card/bootstrap/content.rb
240
+ - lib/card/bootstrap/delegate.rb
241
+ - lib/card/bootstrap/old_component.rb
242
+ - lib/card/bootstrap/tag_method.rb
243
+ - lib/card/bootstrapper.rb
244
244
  - lib/card/lazy_tab.rb
245
245
  - lib/card/tab.rb
246
246
  - lib/javascript/bootstrap_modal_decko.js
@@ -2994,7 +2994,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2994
2994
  - !ruby/object:Gem::Version
2995
2995
  version: '0'
2996
2996
  requirements: []
2997
- rubygems_version: 3.1.6
2997
+ rubygems_version: 3.2.15
2998
2998
  signing_key:
2999
2999
  specification_version: 4
3000
3000
  summary: Bootstrap