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,26 +0,0 @@
1
- # require 'component'
2
-
3
- class Bootstrap
4
- module BasicTags
5
- def html content
6
- add_content String(content).html_safe
7
- ""
8
- end
9
-
10
- Component.def_div_method :div, nil do |opts, extra_args|
11
- prepend_class opts, extra_args.first if extra_args.present?
12
- opts
13
- end
14
-
15
- Component.def_div_method :span, nil do |opts, extra_args|
16
- prepend_class opts, extra_args.first if extra_args.present?
17
- opts
18
- end
19
-
20
- Component.def_tag_method :tag, nil, tag: :yield do |opts, extra_args|
21
- prepend_class opts, extra_args[1] if extra_args[1].present?
22
- opts[:tag] = extra_args[0]
23
- opts
24
- end
25
- end
26
- end
@@ -1,76 +0,0 @@
1
- class Bootstrap
2
- class Component
3
- class Carousel < Component
4
- def render_content
5
- carousel(*@args, &@build_block)
6
- end
7
-
8
- def carousel id, active_index, &block
9
- @id = id
10
- @active_item_index = active_index
11
- @items = []
12
- instance_exec(&block)
13
-
14
- @html.div class: "carousel slide", id: id, "data-ride" => "carousel" do
15
- indicators
16
- items
17
- control_prev
18
- control_next
19
- end
20
- end
21
-
22
- def item content=nil, &block
23
- @items << (content || block)
24
- end
25
-
26
- def items
27
- @html.div class: "carousel-inner", role: "listbox" do
28
- @items.each_with_index do |item, index|
29
- carousel_item item, carousel_item_opts(index)
30
- end
31
- end
32
- end
33
-
34
- def carousel_item_opts index
35
- { class: "carousel-item" }.tap do |opts|
36
- add_class opts, "active" if index == @active_item_index
37
- end
38
- end
39
-
40
- def carousel_item item, html_opts
41
- @html.div html_opts do
42
- item = item.call if item.respond_to?(:call)
43
- @html << item if item.is_a?(String)
44
- end
45
- end
46
-
47
- def control_prev
48
- @html.a class: "carousel-control-prev", href: "##{@id}", role: "button",
49
- "data-slide" => "prev" do
50
- @html.span class: "carousel-control-prev-icon", "aria-hidden" => "true"
51
- @html.span "Previous", class: "sr-only"
52
- end
53
- end
54
-
55
- def control_next
56
- @html.a class: "carousel-control-next", href: "##{@id}", role: "button",
57
- "data-slide": "next" do
58
- @html.span class: "carousel-control-next-icon", "aria-hidden" => "true"
59
- @html.span "Next", class: "sr-only"
60
- end
61
- end
62
-
63
- def indicators
64
- @html.ol class: "carousel-indicators" do
65
- @items.size.times { |i| indicator i }
66
- end
67
- end
68
-
69
- def indicator index
70
- html_opts = { "data-slide-to" => index, "data-target": "##{@id}" }
71
- add_class html_opts, "active" if index == @active_item_index
72
- @html.li html_opts
73
- end
74
- end
75
- end
76
- end
@@ -1,65 +0,0 @@
1
- class Bootstrap
2
- class Component
3
- class Form < Component
4
- def render_content *args
5
- form(*args, &@build_block)
6
- end
7
-
8
- #
9
- # def_tag_method :form, nil, optional_classes: {
10
- # horizontal: "form-horizontal",
11
- # inline: "form-inline"
12
- # }
13
- # def_div_method :group, "form-group"
14
- # def_tag_method :label, nil
15
- # def_tag_method :input, "form-control" do |opts, extra_args|
16
- # type, label = extra_args
17
- # prepend { label label, for: opts[:id] } if label
18
- # opts[:type] = type
19
- # opts
20
- # end
21
-
22
- def form opts={}, &block
23
- add_class opts, "form-horizontal" if opts.delete(:horizontal)
24
- add_class opts, "form-inline" if opts.delete(:inline)
25
- @html.form opts do
26
- instance_exec(&block)
27
- end
28
- end
29
-
30
- def group text=nil, &block
31
- @html.div text, class: "form-group" do
32
- instance_exec(&block)
33
- end
34
- end
35
-
36
- def label text=nil, &block
37
- @html.label text, &block
38
- end
39
-
40
- def input type, text: nil, label: nil, id: nil
41
- @html.input id: id, class: "form-control", type: type do
42
- @html.label label, for: id if label
43
- @html << text if text
44
- end
45
- end
46
-
47
- %i[text password datetime datetime-local date month time
48
- week number email url search tel color].each do |tag|
49
- # def_tag_method tag, "form-control", attributes: { type: tag },
50
- # tag: :input do |opts, extra_args|
51
- # label, = extra_args
52
- # prepend { label label, for: opts[:id] } if label
53
- # opts
54
- # end
55
-
56
- define_method tag do |id:, label:, text: nil|
57
- @html.input id: id, class: "form-control", type: tag do
58
- @html.label label, for: id if label
59
- @html << text
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
@@ -1,63 +0,0 @@
1
- class Bootstrap
2
- class Component
3
- class HorizontalForm < Form
4
- def left_col_width
5
- @child_args.last && @child_args.last[0] || 2
6
- end
7
-
8
- def right_col_width
9
- @child_args.last && @child_args.last[1] || 10
10
- end
11
-
12
- def_tag_method :form, "form-horizontal"
13
-
14
- def_tag_method :label, "control-label" do |opts, _extra_args|
15
- prepend_class opts, "col-sm-#{left_col_width}"
16
- opts
17
- end
18
-
19
- # def_div_method :input, nil do |opts, extra_args, &block|
20
- # type, label = extra_args
21
- # prepend { tag(:label, nil, for: opts[:id]) { label } } if label
22
- # insert { inner_input opts.merge(type: type) }
23
- # { class: "col-sm-#{right_col_width}" }
24
- # end
25
-
26
- def label_col label, id:
27
- @html.label label, for: id, class: "col-sm-#{left_col_width} control-label"
28
- end
29
-
30
- def input type, label:, id:
31
- label_col label, id: id
32
- @html.div class: "col-sm-#{right_col_width}" do
33
- @html.input type: type, id: id, class: "form-control"
34
- end
35
- # block.call class: "col-sm-#{right_col_width}" do
36
- # inner_input opts.merge(type: type)
37
- # end
38
- end
39
-
40
- def_tag_method :inner_input, "form-control", tag: :input
41
- def_div_method :inner_checkbox, "checkbox"
42
-
43
- def_div_method :checkbox, nil do |opts, extra_args|
44
- inner_checkbox do
45
- label do
46
- inner_input "checkbox", extra_args.first, opts
47
- end
48
- end
49
- { class: "col-sm-offset-#{left_col_width} col-sm-#{right_col_width}" }
50
- end
51
-
52
- def checkbox _text, _extra_args
53
- @html.div class: "col-sm-offset-#{left_col_width} col-sm-#{right_col_width}" do
54
- @html.div class: "checkbox" do
55
- label_cllabel do
56
- inner_input "checkbox"
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,105 +0,0 @@
1
- class Bootstrap
2
- class Component
3
- # generate bootstrap column layout
4
- # @example
5
- # layout container: true, fluid: true, class: "hidden" do
6
- # row 6, 6, class: "unicorn" do
7
- # column "horn",
8
- # column "rainbow", class: "colorful"
9
- # end
10
- # end
11
- # @example
12
- # layout do
13
- # row 3, 3, 4, 2, class: "unicorn" do
14
- # [ "horn", "body", "tail", "rainbow"]
15
- # end
16
- # add_html "<span> some extra html</span>"
17
- # row 6, 6, ["unicorn", "rainbow"], class: "horn"
18
- # end
19
- class Layout < OldComponent
20
- def render
21
- @rendered = begin
22
- render_content
23
- @content[-1]
24
- end
25
- end
26
-
27
- def render_content
28
- content = instance_exec(*@args, &@build_block)
29
- add_content content
30
- opts = @args.first
31
- return unless opts&.delete(:container)
32
-
33
- content = @content.pop
34
- @content = ["".html_safe]
35
- container content, opts
36
- end
37
-
38
- add_div_method :container, nil do |opts, _extra_args|
39
- prepend_class opts, opts.delete(:fluid) ? "container-fluid" : "container"
40
- opts
41
- end
42
-
43
- # @param args column widths, column content and html attributes
44
- # @example
45
- # row 6, 6, ["col one", "col two"], class: "count", id: "count"
46
- # @example
47
- # row md: 12, xs: 8, "single column content"
48
- # @example
49
- # row md: [1, 11], xs: [2, 10] do
50
- # col "A"
51
- # col "B"
52
- # end
53
- add_div_method :row, "row", content_processor: :column do |opts, extra_args|
54
- cols_content = extra_args.pop if extra_args.last.is_a? Array
55
- [opts, col_widths(extra_args, opts), cols_content].compact
56
- end
57
-
58
- # default column width type is for medium devices (col-md-)
59
- add_div_method :column, nil do |opts, _extra_args|
60
- @child_args.last.each do |medium, size|
61
- if medium == :xs
62
- prepend_class opts, "col-#{size.shift}"
63
- else
64
- prepend_class opts, "col-#{medium}-#{size.shift}"
65
- end
66
- end
67
- opts
68
- end
69
-
70
- alias_method :col, :column
71
-
72
- private
73
-
74
- def standardize_row_args args
75
- opts = args.last.is_a?(Hash) ? args.pop : {}
76
- cols = (args.last.is_a?(Array) || args.last.is_a?(String)) &&
77
- Array.wrap(args.pop)
78
- [cols, opts, col_widths(args, opts)]
79
- end
80
-
81
- def col_widths args, opts
82
- opts = args.pop if args.one? && args.last.is_a?(Hash)
83
- if args.present?
84
- col_widths_from_args args
85
- else
86
- col_widths_from_opts opts
87
- end
88
- end
89
-
90
- def col_widths_from_args args
91
- raise Error, "bad argument" unless args.all? { |a| a.is_a? Integer }
92
-
93
- { md: Array.wrap(args) }
94
- end
95
-
96
- def col_widths_from_opts opts
97
- %i[lg xs sm md].each_with_object({}) do |k, cols_w|
98
- next unless (widths = opts.delete(k))
99
-
100
- cols_w[k] = Array.wrap widths
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,9 +0,0 @@
1
- class Bootstrap
2
- class Component
3
- class Panel < OldComponent
4
- def_div_method :panel, "card"
5
- def_div_method :heading, "card-header"
6
- def_div_method :body, "card-body"
7
- end
8
- end
9
- end
@@ -1,108 +0,0 @@
1
- class Bootstrap
2
- # render components of bootstrap library
3
- class Component
4
- extend ComponentClass
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
- @html = Builder::XmlMarkup.new
15
- end
16
-
17
- def render
18
- @rendered = render_content
19
- end
20
-
21
- def prepend &block
22
- tmp = @content.pop
23
- instance_exec(&block)
24
- @content << tmp
25
- end
26
-
27
- def insert &block
28
- instance_exec(&block)
29
- end
30
-
31
- def append &block
32
- @append[-1] << block
33
- end
34
-
35
- def wrap tag=nil, &block
36
- @wrap[-1] << (block_given? ? block : tag)
37
- end
38
-
39
- def card
40
- @context.context.card
41
- end
42
-
43
- private
44
-
45
- def tag_method_opts args, html_class, tag_opts, &tag_opts_block
46
- opts = {}
47
- _blah, opts, _blah = standardize_args args, &tag_opts_block if block_given?
48
- add_classes opts, html_class, tag_opts.delete(:optional_classes)
49
- opts
50
- end
51
-
52
- def render_content
53
- # if @build_block.arity > 0
54
- instance_exec(*@args, &@build_block)
55
- end
56
-
57
- def generate_content content, processor, &block
58
- content = instance_exec(&block) if block.present?
59
- return content if !processor || !content.is_a?(Array)
60
-
61
- content.each { |item| send processor, item }
62
- ""
63
- end
64
-
65
- def with_child_args args
66
- @child_args << args if args.present?
67
- yield.tap { @child_args.pop if args.present? }
68
- end
69
-
70
- def add_content content
71
- @content[-1] << "\n#{content}".html_safe if content.present?
72
- end
73
-
74
- def standardize_args args, &block
75
- opts = standardize_opts args
76
- items = items_from_args args
77
- opts, args = standardize_block_args opts, args, &block if block.present?
78
-
79
- [items, opts, args]
80
- end
81
-
82
- def standardize_opts args
83
- args.last.is_a?(Hash) ? args.pop : {}
84
- end
85
-
86
- def items_from_args args
87
- ((args.one? && args.last.is_a?(String)) || args.last.is_a?(Array)) && args.pop
88
- end
89
-
90
- def standardize_block_args opts, args, &block
91
- instance_exec(opts, args, &block).tap do |s_opts, _s_args|
92
- unless s_opts.is_a? Hash
93
- raise Card::Error, "first return value of a tag block has to be a hash"
94
- end
95
- end
96
- end
97
-
98
- def add_classes opts, html_class, optional_classes
99
- prepend_class opts, html_class if html_class
100
- Array.wrap(optional_classes).each do |k, v|
101
- prepend_class opts, v if opts.delete k
102
- end
103
- end
104
-
105
- include BasicTags
106
- include Delegate
107
- end
108
- end