card-mod-bootstrap 0.11.7 → 0.12.0

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.
@@ -1,28 +0,0 @@
1
- class Bootstrap
2
- module ComponentLoader
3
- def load_components
4
- components.each do |component|
5
- require_relative "component/#{component}"
6
- include_component component
7
- end
8
- end
9
-
10
- def include_component component
11
- component_class = to_const component.camelcase
12
- define_method component do |*args, &block|
13
- component_class.render self, *args, &block
14
- end
15
- end
16
-
17
- def components
18
- path = File.expand_path "component/*.rb", __dir__
19
- Dir.glob(path).map do |file|
20
- File.basename file, ".rb"
21
- end
22
- end
23
-
24
- def to_const name
25
- self.class.const_get "::Bootstrap::Component::#{name.camelcase}"
26
- end
27
- end
28
- end
@@ -1,40 +0,0 @@
1
- class Bootstrap
2
- # shared methods for OldComponent and TagMethod
3
- module Content
4
- private
5
-
6
- def process_collected_content tag_name, opts
7
- collected_content = @content.pop
8
- tag_name = opts.delete(:tag) if tag_name == :yield
9
- add_content content_tag(tag_name, collected_content, opts, false)
10
- end
11
-
12
- def process_content &content_block
13
- content, opts = yield
14
- wrappers = @wrap.pop
15
- if wrappers.present?
16
- process_wrappers wrappers, content, &content_block
17
- else
18
- add_content content
19
- end
20
- opts
21
- end
22
-
23
- def process_append
24
- @append.pop.each do |block|
25
- add_content instance_exec(&block)
26
- end
27
- end
28
-
29
- def process_wrappers wrappers, content, &content_block
30
- while wrappers.present?
31
- wrapper = wrappers.shift
32
- if wrapper.is_a? Symbol
33
- send wrapper, &content_block
34
- else
35
- instance_exec content, &wrappers.shift
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,16 +0,0 @@
1
- class Bootstrap
2
- module Delegate
3
- def method_missing method_name, *args, &block
4
- # return super unless @context.respond_to? method_name
5
- if block_given?
6
- @context.send(method_name, *args, &block)
7
- else
8
- @context.send(method_name, *args)
9
- end
10
- end
11
-
12
- def respond_to_missing? method_name, _include_private=false
13
- @context.respond_to? method_name
14
- end
15
- end
16
- end
@@ -1,103 +0,0 @@
1
- class Bootstrap
2
- # not-yet-obviated component handling
3
- class OldComponent < Component
4
- include Content
5
-
6
- def initialize context, *args, &block
7
- @context = context
8
- @content = ["".html_safe]
9
- @args = args
10
- @child_args = []
11
- @append = []
12
- @wrap = []
13
- @build_block = block
14
- end
15
-
16
- class << self
17
- def render format, *args, &block
18
- new(format, *args, &block).render
19
- end
20
-
21
- # Like add_tag_method but always generates a div tag
22
- # The tag option is not available
23
- def add_div_method name, html_class, opts={}, &tag_block
24
- add_tag_method name, html_class, opts.merge(tag: :div), &tag_block
25
- end
26
-
27
- # Defines a method that generates a html tag
28
- # @param name [Symbol, String] the name of the method. If no :tag option in tag_opts is defined then the name is also the name of the tag that the method generates
29
- # @param html_class [String] a html class that is added to tag. Use nil if you don't want a html_class
30
- # @param tag_opts [Hash] additional argument that will be added to the tag
31
- # @option tag_opts [Symbol, String] tag the name of the tag
32
- # @example
33
- # add_tag_method :link, "known-link", tag: :a, id: "uniq-link"
34
- # link # => <a class="known-link" id="uniq-link"></a>
35
- def add_tag_method name, html_class, tag_opts={}, &tag_block
36
- define_method name do |*args, &block|
37
- process_tag tag_opts[:tag] || name do
38
- content, opts, new_child_args = standardize_args args, &tag_block
39
- add_classes opts, html_class, tag_opts.delete(:optional_classes)
40
- if (attributes = tag_opts.delete(:attributes))
41
- opts.merge! attributes
42
- end
43
-
44
- content = with_child_args new_child_args do
45
- generate_content content,
46
- tag_opts[:content_processor],
47
- &block
48
- end
49
-
50
- [content, opts]
51
- end
52
- end
53
- end
54
-
55
- alias_method :def_div_method, :add_div_method
56
- alias_method :def_tag_method, :add_tag_method
57
- end
58
-
59
- def render
60
- @rendered = begin
61
- render_content
62
- @content[-1]
63
- end
64
- end
65
-
66
- private
67
-
68
- def process_tag tag_name, &content_block
69
- @content.push "".html_safe
70
- @append << []
71
- @wrap << []
72
-
73
- opts = process_content(&content_block)
74
- process_collected_content tag_name, opts
75
- process_append
76
- ""
77
- end
78
-
79
- # include BasicTags
80
- def html content
81
- add_content String(content).html_safe
82
- ""
83
- end
84
-
85
- add_div_method :div, nil do |opts, extra_args|
86
- prepend_class opts, extra_args.first if extra_args.present?
87
- opts
88
- end
89
-
90
- add_div_method :span, nil do |opts, extra_args|
91
- prepend_class opts, extra_args.first if extra_args.present?
92
- opts
93
- end
94
-
95
- add_tag_method :tag, nil, tag: :yield do |opts, extra_args|
96
- prepend_class opts, extra_args[1] if extra_args[1].present?
97
- opts[:tag] = extra_args[0]
98
- opts
99
- end
100
-
101
- include Delegate
102
- end
103
- end
@@ -1,54 +0,0 @@
1
- class Bootstrap
2
- # support html tag generation
3
- class TagMethod
4
- include Content
5
-
6
- def initialize component, name, html_class, tag_opts={}, &tag_block
7
- @component = component
8
- @name = name
9
- @html_class = html_class
10
- @tag_opts = tag_opts
11
- @tag_block = tag_block
12
- @append = []
13
- @wrap = []
14
- @xm = Builder::XmlMarkup.new
15
- end
16
-
17
- def call *_args, &content_block
18
- component.content.push "".html_safe
19
-
20
- opts = process_content(&content_block)
21
- process_collected_content tag_name, opts
22
- process_append
23
- ""
24
- end
25
-
26
- def method_missing method, *args, &block
27
- return super unless respond_to_missing? method
28
-
29
- @component.send method, *args, &block
30
- end
31
-
32
- def respond_to_missing? method, _include_private=false
33
- @component.respond_to? method
34
- end
35
-
36
- def prepend &block
37
- tmp = @content.pop
38
- instance_exec(&block)
39
- @content << tmp
40
- end
41
-
42
- def wrap &block
43
- instance_exec(&block)
44
- end
45
-
46
- def append &block
47
- @append[-1] << block
48
- end
49
-
50
- def wrapInner tag=nil, &block
51
- @wrap[-1] << (block_given? ? block : tag)
52
- end
53
- end
54
- end
data/lib/bootstrap.rb DELETED
@@ -1,18 +0,0 @@
1
- require "bootstrap/component_loader"
2
- require "bootstrap/component"
3
-
4
- class Bootstrap
5
- include Delegate
6
- extend ComponentLoader
7
- load_components
8
-
9
- attr_reader :context
10
-
11
- def initialize context=nil
12
- @context = context
13
- end
14
-
15
- def render *args, &block
16
- instance_exec(*args, &block)
17
- end
18
- end
data/lib/bootstrapper.rb DELETED
@@ -1,16 +0,0 @@
1
- require "bootstrap"
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