tailmix 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/examples/interactive_component.rb +42 -0
- data/lib/tailmix/action.rb +27 -0
- data/lib/tailmix/manager.rb +28 -0
- data/lib/tailmix/schema.rb +24 -1
- data/lib/tailmix/version.rb +1 -1
- data/lib/tailmix.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b60ee0099a1c65d9cab150deed3820c382c472029fc35f0f7b4f3d2c8f7c7a45
|
|
4
|
+
data.tar.gz: c3744db3320269d2a04b332bb039ee3e9d7a3b0bfac334bfe79cc25fafdf2145
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4baebd46d43f04837c23e390e8b33633eb95542e36015090c2c23663cba343a7be759b4c01a4a81268517419c531321bfe7e3ff4dbd6350268c45bbc6d476365
|
|
7
|
+
data.tar.gz: 6a0544fe9a7bd949f466b6d5bca583e4ec7c9a6d8a2e342609c12accb0708a4ffd8d868512d80b9a679b807042025c24e287da26e8f8370893e13a3038aaac3d
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../lib/tailmix"
|
|
4
|
+
|
|
5
|
+
class InteractiveComponent
|
|
6
|
+
include Tailmix
|
|
7
|
+
|
|
8
|
+
tailmix do
|
|
9
|
+
element :container, "p-4 rounded-md"
|
|
10
|
+
element :label, "font-bold"
|
|
11
|
+
|
|
12
|
+
action :highlight, behavior: :toggle do
|
|
13
|
+
element :container, "ring-2 ring-blue-500 bg-blue-50"
|
|
14
|
+
element :label, "text-blue-700"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
attr_reader :classes
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
@classes = tailmix
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def toggle_highlight
|
|
25
|
+
@classes.actions.highlight.apply!
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def render
|
|
29
|
+
# ...
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
component = InteractiveComponent.new
|
|
34
|
+
puts "Initial container: '#{component.classes.container}'"
|
|
35
|
+
# => Initial container: 'p-4 rounded-md'
|
|
36
|
+
|
|
37
|
+
component.toggle_highlight
|
|
38
|
+
puts "After highlight: '#{component.classes.container}'"
|
|
39
|
+
# => After highlight: 'p-4 rounded-md ring-2 ring-blue-500 bg-blue-50'
|
|
40
|
+
|
|
41
|
+
puts "JSON Recipe: #{component.classes.actions.highlight.to_json}"
|
|
42
|
+
# => JSON Recipe: {"behavior":"toggle","classes":{"container":"ring-2...","label":"text-blue-700"}}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Tailmix
|
|
6
|
+
class Action
|
|
7
|
+
def initialize(manager, behavior:, classes_by_part:)
|
|
8
|
+
@manager = manager
|
|
9
|
+
@behavior = behavior
|
|
10
|
+
@classes_by_part = classes_by_part
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def apply!
|
|
14
|
+
@classes_by_part.each do |part_name, classes|
|
|
15
|
+
part_object = @manager.public_send(part_name)
|
|
16
|
+
part_object.public_send(@behavior, classes)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_json(*_args)
|
|
21
|
+
{
|
|
22
|
+
behavior: @behavior,
|
|
23
|
+
classes: @classes_by_part
|
|
24
|
+
}.to_json
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/tailmix/manager.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative "resolver"
|
|
4
4
|
require_relative "part"
|
|
5
5
|
require_relative "utils"
|
|
6
|
+
require_relative "action"
|
|
6
7
|
|
|
7
8
|
module Tailmix
|
|
8
9
|
class Manager
|
|
@@ -34,6 +35,33 @@ module Tailmix
|
|
|
34
35
|
@part_objects.key?(method_name.to_sym) || super
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
def actions
|
|
39
|
+
@action_proxy ||= ActionProxy.new(self, @schema)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class ActionProxy
|
|
43
|
+
def initialize(manager, schema)
|
|
44
|
+
@manager = manager
|
|
45
|
+
@schema = schema
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def method_missing(method_name, *args, &block)
|
|
49
|
+
action_name = method_name.to_sym
|
|
50
|
+
|
|
51
|
+
if @schema.actions.key?(action_name)
|
|
52
|
+
action_definition = @schema.actions[action_name]
|
|
53
|
+
|
|
54
|
+
Action.new(@manager, **action_definition)
|
|
55
|
+
else
|
|
56
|
+
super
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
61
|
+
@schema.actions.key?(method_name.to_sym) || super
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
37
65
|
private
|
|
38
66
|
|
|
39
67
|
def rebuild_parts!
|
data/lib/tailmix/schema.rb
CHANGED
|
@@ -4,15 +4,38 @@ require_relative "element"
|
|
|
4
4
|
|
|
5
5
|
module Tailmix
|
|
6
6
|
class Schema
|
|
7
|
-
attr_reader :elements
|
|
7
|
+
attr_reader :elements, :actions
|
|
8
8
|
|
|
9
9
|
def initialize(&block)
|
|
10
10
|
@elements = {}
|
|
11
|
+
@actions = {}
|
|
11
12
|
instance_eval(&block) if block_given?
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def element(name, base_classes, &block)
|
|
15
16
|
@elements[name.to_sym] = Element.new(base_classes, &block)
|
|
16
17
|
end
|
|
18
|
+
|
|
19
|
+
def action(name, behavior: :toggle, &block)
|
|
20
|
+
builder = ActionBuilder.new
|
|
21
|
+
builder.instance_eval(&block)
|
|
22
|
+
|
|
23
|
+
@actions[name.to_sym] = {
|
|
24
|
+
behavior: behavior,
|
|
25
|
+
classes_by_part: builder.classes_by_part
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class ActionBuilder
|
|
30
|
+
attr_reader :classes_by_part
|
|
31
|
+
|
|
32
|
+
def initialize
|
|
33
|
+
@classes_by_part = {}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def element(name, classes)
|
|
37
|
+
@classes_by_part[name.to_sym] = classes
|
|
38
|
+
end
|
|
39
|
+
end
|
|
17
40
|
end
|
|
18
41
|
end
|
data/lib/tailmix/version.rb
CHANGED
data/lib/tailmix.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tailmix
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Fokin
|
|
@@ -68,8 +68,10 @@ files:
|
|
|
68
68
|
- LICENSE.txt
|
|
69
69
|
- README.md
|
|
70
70
|
- Rakefile
|
|
71
|
+
- examples/interactive_component.rb
|
|
71
72
|
- examples/status_badge_component.rb
|
|
72
73
|
- lib/tailmix.rb
|
|
74
|
+
- lib/tailmix/action.rb
|
|
73
75
|
- lib/tailmix/dimension.rb
|
|
74
76
|
- lib/tailmix/element.rb
|
|
75
77
|
- lib/tailmix/manager.rb
|