Skip to content

Commit

Permalink
essence class reworkings
Browse files Browse the repository at this point in the history
  • Loading branch information
elvinaspredkelis committed Jan 2, 2025
1 parent 5b3c3b7 commit f0ee22a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 37 deletions.
100 changes: 63 additions & 37 deletions ruby/lib/essence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,78 @@ module Essence
autoload :Avatar, "essence/components/avatar"
autoload :Badge, "essence/components/badge"
autoload :Button, "essence/components/button"
# autoload :Essence, "essence/components/essence" # Base component
autoload :Essence, "essence/components/essence" # Base component
autoload :Link, "essence/components/link"
autoload :Row, "essence/components/row"
autoload :Skeleton, "essence/components/skeleton"

autoload :CLI, "essence/cli"

# Components
# Class names and classes are separated to avoid loading in Phlex into the CLI tooling

def self.component_class_names
@component_class_names ||= {
essence: "Essence::Essence",
accordion: "Essence::Accordion",
avatar: "Essence::Avatar",
badge: "Essence::Badge",
button: "Essence::Button",
link: "Essence::Link",
row: "Essence::Row",
skeleton: "Essence::Skeleton",
}
end
class << self
# CONFIGURATION
def configuration
@configuration ||= Configuration.new
end

def self.component_classes
@components_classes ||= {
essence: ::Essence::Essence,
accordion: ::Essence::Accordion,
avatar: ::Essence::Avatar,
badge: ::Essence::Badge,
button: ::Essence::Button,
link: ::Essence::Link,
row: ::Essence::Row,
skeleton: ::Essence::Skeleton,
}
end
def configure
yield configuration
end

def self.component_names
@component_names ||= component_class_names.keys
end
# COMPONENTS
def components
@components ||= {
accordion: {
name: "Accordion",
class_name: "Essence::Accordion",
stimulus: false
},
avatar: {
name: "Avatar",
class_name: "Essence::Avatar",
stimulus: false
},
badge: {
name: "Badge",
class_name: "Essence::Badge",
stimulus: false
},
button: {
name: "Button",
class_name: "Essence::Button",
stimulus: false
},
link: {
name: "Link",
class_name: "Essence::Link",
stimulus: false
},
row: {
name: "Row",
class_name: "Essence::Row",
stimulus: false
},
skeleton: {
name: "Skeleton",
class_name: "Essence::Skeleton",
stimulus: false
}
}
end

# Configuration
def self.configuration
@configuration ||= Configuration.new
end
def component_keys
@component_keys ||= components.keys
end

def component_names
@component_names ||= components.transform_values { |v| v[:name] }
end

def component_class_names
@component_class_names ||= components.transform_values { |v| v[:class_name] }
end

def self.configure
yield configuration
def component_classes
@component_classes ||= component_class_names.transform_values { |v| Object.const_get(v) }
end
end
end
3 changes: 3 additions & 0 deletions ruby/lib/essence/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module Commands
COMPONENTS_DIR = Pathname.new(File.expand_path("components", __dir__))
DESTINATION_DIR = Pathname.new(File.expand_path(Dir.pwd)).join(::Essence.configuration.phlex_components_path)

STIMULUS_CONTROLLERS_DIR = Pathname.new(File.expand_path(__dir__)).join("essence/stimulus")
STIMULUS_CONTROLLERS_DESTINATION_DIR = Pathname.new(File.expand_path(Dir.pwd)).join(::Essence.configuration.stimulus_controller_path)

COMPONENT_DEFINITION_PREFIX = "class Essence::"
COMPONENT_DEFINITION_SUFFIX = "< Essence::Essence"
PHLEX_COMPONENT_DEFINITION_PREFIX = "class Components::"
Expand Down

0 comments on commit f0ee22a

Please sign in to comment.