essence 0.2.3 → 0.3.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/lib/essence/cli/add.rb +10 -2
- data/lib/essence/cli.rb +15 -1
- data/lib/essence/components/skeleton.rb +10 -0
- data/lib/essence/components/tabs.rb +58 -0
- data/lib/essence/configuration.rb +11 -0
- data/lib/essence/version.rb +1 -1
- data/lib/essence.rb +77 -29
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a05b5cc8ee41e915b4d8646bb7357451484b0d36f9893deb21f58c540838d86
|
4
|
+
data.tar.gz: 27b53f351c8b5fb5b6718cdf2c5b4b4834251042dc48657dd2a70ac42e4865be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f3d8aad9655e9a3d86ca7db39d6bdc03f608bfe6bc79f6cea64591340449b19fa4c9ffbbfe0f8939472b870dcf57508f1a1b0d9d29504757b49e3636ef3c074
|
7
|
+
data.tar.gz: 846b1a2df22849a2c8cdb9b8d44a8e7dbc3204e4b90e68b93b8d355ae6aa86076da3206c00594a54d23b714b37562cf38a5e9070bcaf9e590d3120a372dceb16
|
data/lib/essence/cli/add.rb
CHANGED
@@ -9,8 +9,16 @@ module Essence
|
|
9
9
|
|
10
10
|
def call(*args)
|
11
11
|
component_name = args[0][:component_name]
|
12
|
+
key = component_name.to_sym
|
13
|
+
has_stimulus_controller = Essence.components[key][:stimulus] || false
|
12
14
|
|
13
|
-
return puts "> #{component_name}: component unsupported" unless Essence.
|
15
|
+
return puts "> #{component_name}: component unsupported" unless Essence.component_keys.include?(key)
|
16
|
+
puts "> [Essence] #{Essence.components[key][:name]}"
|
17
|
+
|
18
|
+
if has_stimulus_controller
|
19
|
+
Essence::CLI::Commands.copy_controller(component_name:)
|
20
|
+
puts "> [Stimulus] #{Essence::CLI::Commands::STIMULUS_CONTROLLERS_DESTINATION_DIR.join("#{component_name}_controller.js")}"
|
21
|
+
end
|
14
22
|
|
15
23
|
Essence::CLI::Commands.copy_component(component_name:)
|
16
24
|
Essence::CLI::Commands.replace_component_contents(component_name:)
|
@@ -20,7 +28,7 @@ module Essence
|
|
20
28
|
to: Essence::CLI::Commands::PHLEX_COMPONENT_DEFINITION_SUFFIX
|
21
29
|
)
|
22
30
|
|
23
|
-
puts ">
|
31
|
+
puts "> [Phlex] #{Essence::CLI::Commands::DESTINATION_DIR.join("#{component_name}.rb")}"
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
data/lib/essence/cli.rb
CHANGED
@@ -17,8 +17,12 @@ module Essence
|
|
17
17
|
extend Dry::CLI::Registry
|
18
18
|
|
19
19
|
# Constants
|
20
|
+
STIMULUS_CONTROLLERS_DIR = Pathname.new(::Essence.root_path).join("essence/stimulus")
|
21
|
+
STIMULUS_CONTROLLERS_DESTINATION_DIR = Pathname.new(File.expand_path(Dir.pwd)).join(::Essence.configuration.stimulus_controller_path)
|
22
|
+
|
20
23
|
COMPONENTS_DIR = Pathname.new(File.expand_path("components", __dir__))
|
21
|
-
DESTINATION_DIR = Pathname.new(File.expand_path(Dir.pwd)).join(
|
24
|
+
DESTINATION_DIR = Pathname.new(File.expand_path(Dir.pwd)).join(::Essence.configuration.phlex_components_path)
|
25
|
+
|
22
26
|
COMPONENT_DEFINITION_PREFIX = "class Essence::"
|
23
27
|
COMPONENT_DEFINITION_SUFFIX = "< Essence::Essence"
|
24
28
|
PHLEX_COMPONENT_DEFINITION_PREFIX = "class Components::"
|
@@ -32,6 +36,7 @@ module Essence
|
|
32
36
|
private
|
33
37
|
|
34
38
|
# UTILITIES
|
39
|
+
# PHLEX COMPONENTS
|
35
40
|
def self.copy_component(component_name:)
|
36
41
|
source_path = COMPONENTS_DIR.join("#{component_name}.rb")
|
37
42
|
destination_path = DESTINATION_DIR.join("#{component_name}.rb")
|
@@ -58,6 +63,15 @@ module Essence
|
|
58
63
|
|
59
64
|
FileUtils.mv(from, to)
|
60
65
|
end
|
66
|
+
|
67
|
+
# STIMULUS CONTROLLERS
|
68
|
+
def self.copy_controller(component_name:)
|
69
|
+
source_path = STIMULUS_CONTROLLERS_DIR.join("#{component_name}_controller.js")
|
70
|
+
destination_path = STIMULUS_CONTROLLERS_DESTINATION_DIR.join("#{component_name}_controller.js")
|
71
|
+
|
72
|
+
FileUtils.mkdir_p(STIMULUS_CONTROLLERS_DESTINATION_DIR)
|
73
|
+
FileUtils.copy(source_path, destination_path)
|
74
|
+
end
|
61
75
|
end
|
62
76
|
end
|
63
77
|
end
|
@@ -1,5 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# A skeleton component is used to show a loading state.
|
4
|
+
#
|
5
|
+
# ==== Examples
|
6
|
+
#
|
7
|
+
# render Skeleton.new(class: "w-32 h-6")
|
8
|
+
#
|
9
|
+
# ==== Documentation
|
10
|
+
#
|
11
|
+
# https://essence.primevise.com/components/skeleton
|
12
|
+
#
|
3
13
|
class Essence::Skeleton < Essence::Essence
|
4
14
|
BASE = "animate-pulse bg-gray-200/55 rounded-xs"
|
5
15
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Essence::Tabs < Essence::Essence
|
4
|
+
BASE = "rounded-lg overflow-hidden"
|
5
|
+
TAB_BASE = "inline-flex items-center justify-center w-fit rounded-xs border border-transparent font-medium transition duration-150 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed hover:opacity-90 text-xs px-3 py-2 gap-1.5 text-gray-900 bg-transparent hover:bg-gray-200 hover:text-gray-800"
|
6
|
+
TAB_LIST_BASE = "flex items-center gap-2 py-2 border-b"
|
7
|
+
PANEL_BASE = "aria-hidden:hidden p-4"
|
8
|
+
|
9
|
+
attr_reader :attributes
|
10
|
+
|
11
|
+
def initialize(**attributes)
|
12
|
+
super(**attributes)
|
13
|
+
@attributes[:class] = merge_classes([ BASE, @attributes[:class] ])
|
14
|
+
end
|
15
|
+
|
16
|
+
def view_template(&)
|
17
|
+
div(**attributes, &)
|
18
|
+
end
|
19
|
+
|
20
|
+
def menu(**mattributes, &)
|
21
|
+
mattributes[:class] = merge_classes([ TAB_LIST_BASE, mattributes[:class] ])
|
22
|
+
|
23
|
+
div(**mattributes, &)
|
24
|
+
end
|
25
|
+
|
26
|
+
def tab(key: :general, **mattributes, &)
|
27
|
+
mattributes[:id] = "tab-#{key}"
|
28
|
+
mattributes[:class] = merge_classes([ TAB_BASE, mattributes[:class] ])
|
29
|
+
mattributes[:data] = {
|
30
|
+
essence__tabs_target: "tab",
|
31
|
+
essence__tabs_panel_id_param: "panel-#{key}",
|
32
|
+
action: "essence--tabs#setActiveTab keydown.left->essence--tabs#previous keydown.right->essence--tabs#next"
|
33
|
+
}
|
34
|
+
|
35
|
+
button(**mattributes, &)
|
36
|
+
end
|
37
|
+
|
38
|
+
def panel(key: :general, **mattributes, &)
|
39
|
+
mattributes[:id] = "panel-#{key}"
|
40
|
+
mattributes[:class] = merge_classes([ PANEL_BASE, mattributes[:class] ])
|
41
|
+
mattributes[:data] = {
|
42
|
+
essence__tabs_target: "panel"
|
43
|
+
}
|
44
|
+
|
45
|
+
div(**mattributes, &)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def default_attributes
|
51
|
+
{
|
52
|
+
data: {
|
53
|
+
controller: "essence--tabs",
|
54
|
+
essence__tabs_active_value: "panel-general"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Essence
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :phlex_components_path
|
4
|
+
attr_accessor :stimulus_controller_path
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@phlex_components_path = "app/components"
|
8
|
+
@stimulus_controller_path = "app/javascript/controllers/essence"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/essence/version.rb
CHANGED
data/lib/essence.rb
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
require "tailwind_merge"
|
4
4
|
|
5
|
+
require_relative "essence/configuration"
|
6
|
+
|
5
7
|
module Essence
|
6
8
|
# Autoloading
|
9
|
+
# Components
|
7
10
|
autoload :Accordion, "essence/components/accordion"
|
8
11
|
autoload :Avatar, "essence/components/avatar"
|
9
12
|
autoload :Badge, "essence/components/badge"
|
@@ -13,38 +16,83 @@ module Essence
|
|
13
16
|
autoload :Row, "essence/components/row"
|
14
17
|
autoload :Skeleton, "essence/components/skeleton"
|
15
18
|
|
19
|
+
# CLI
|
16
20
|
autoload :CLI, "essence/cli"
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@component_class_names ||= {
|
23
|
-
essence: "Essence::Essence",
|
24
|
-
accordion: "Essence::Accordion",
|
25
|
-
avatar: "Essence::Avatar",
|
26
|
-
badge: "Essence::Badge",
|
27
|
-
button: "Essence::Button",
|
28
|
-
link: "Essence::Link",
|
29
|
-
row: "Essence::Row",
|
30
|
-
skeleton: "Essence::Skeleton",
|
31
|
-
}
|
32
|
-
end
|
22
|
+
class << self
|
23
|
+
def root_path
|
24
|
+
File.dirname(__dir__)
|
25
|
+
end
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
27
|
+
# CONFIGURATION
|
28
|
+
def configuration
|
29
|
+
@configuration ||= Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure
|
33
|
+
yield configuration
|
34
|
+
end
|
35
|
+
|
36
|
+
# COMPONENTS
|
37
|
+
def components
|
38
|
+
@components ||= {
|
39
|
+
accordion: {
|
40
|
+
name: "Accordion",
|
41
|
+
class_name: "Essence::Accordion",
|
42
|
+
stimulus: false
|
43
|
+
},
|
44
|
+
avatar: {
|
45
|
+
name: "Avatar",
|
46
|
+
class_name: "Essence::Avatar",
|
47
|
+
stimulus: false
|
48
|
+
},
|
49
|
+
badge: {
|
50
|
+
name: "Badge",
|
51
|
+
class_name: "Essence::Badge",
|
52
|
+
stimulus: false
|
53
|
+
},
|
54
|
+
button: {
|
55
|
+
name: "Button",
|
56
|
+
class_name: "Essence::Button",
|
57
|
+
stimulus: false
|
58
|
+
},
|
59
|
+
link: {
|
60
|
+
name: "Link",
|
61
|
+
class_name: "Essence::Link",
|
62
|
+
stimulus: false
|
63
|
+
},
|
64
|
+
row: {
|
65
|
+
name: "Row",
|
66
|
+
class_name: "Essence::Row",
|
67
|
+
stimulus: false
|
68
|
+
},
|
69
|
+
skeleton: {
|
70
|
+
name: "Skeleton",
|
71
|
+
class_name: "Essence::Skeleton",
|
72
|
+
stimulus: false
|
73
|
+
},
|
74
|
+
tabs: {
|
75
|
+
name: "Tabs",
|
76
|
+
class_name: "Essence::Tabs",
|
77
|
+
stimulus: true
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def component_keys
|
83
|
+
@component_keys ||= components.keys
|
84
|
+
end
|
85
|
+
|
86
|
+
def component_names
|
87
|
+
@component_names ||= components.transform_values { |v| v[:name] }
|
88
|
+
end
|
89
|
+
|
90
|
+
def component_class_names
|
91
|
+
@component_class_names ||= components.transform_values { |v| v[:class_name] }
|
92
|
+
end
|
46
93
|
|
47
|
-
|
48
|
-
|
94
|
+
def component_classes
|
95
|
+
@component_classes ||= component_class_names.transform_values { |v| Object.const_get(v) }
|
96
|
+
end
|
49
97
|
end
|
50
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: essence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elvinas Predkelis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-cli
|
@@ -84,6 +84,8 @@ files:
|
|
84
84
|
- lib/essence/components/link.rb
|
85
85
|
- lib/essence/components/row.rb
|
86
86
|
- lib/essence/components/skeleton.rb
|
87
|
+
- lib/essence/components/tabs.rb
|
88
|
+
- lib/essence/configuration.rb
|
87
89
|
- lib/essence/version.rb
|
88
90
|
homepage: https://rubygems.org/gems/essence
|
89
91
|
licenses:
|