classic 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +139 -0
- data/Rakefile +12 -0
- data/lib/classic/configuration.rb +14 -0
- data/lib/classic/manager.rb +174 -0
- data/lib/classic/railtie.rb +19 -0
- data/lib/classic/string_ext.rb +7 -0
- data/lib/classic/version.rb +5 -0
- data/lib/classic.rb +39 -0
- data/sig/classic.rbs +4 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 47ef7851e58eaa92f7c1175bb3acda23fd987a694c6583b883b3ac1d6cb9d863
|
4
|
+
data.tar.gz: 561ae1ed4743c29967c7c30472e5609c36b527221920ffa4d2c24dfdce57fbec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04aec15920dcdb77462ca5c9c55bfb55136bed223b994be19cc7770c9b1ff80e8654eacc13a1acd3d1f627a3bfa263baa6c8e1733ff98aef3df06827e535b92d
|
7
|
+
data.tar.gz: 1d12381b0e627f796ed7d31f9421f4396096f9fe0df89a105203d8c7d46ec41ab01fd2962be172ced2a17444ac1174e8a47e674e944d802051dae8967f53ed92
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Jiren Patel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Classic
|
2
|
+
|
3
|
+
A comprehensive utility library designed to standardize and simplify the management of styles across web application and cache styles. This library facilitates consistent styling, theme management and dynamically combine components styles i.e varient,size.
|
4
|
+
|
5
|
+
## What's in it?
|
6
|
+
|
7
|
+
Picture this: You're a web developer tired of juggling stylesheets like a circus performer with too many flaming torches. Well, grab your virtual wand because we're about to turn that CSS circus into a well-choreographed dance party!
|
8
|
+
|
9
|
+
1. Manages all your component or html elements styles in single place.
|
10
|
+
|
11
|
+
2. One change of text and POOF! Your entire app's theme changes faster than you can say "abracadabra"
|
12
|
+
|
13
|
+
3. No more playing "Find and Replace" across 100 files when your client decides hot pink isn't their brand color anymore.
|
14
|
+
|
15
|
+
4. Mix and match variants like you're playing dress-up with your code.
|
16
|
+
|
17
|
+
5. "Small", "Large", "Primary", "Secondary" - it's like a fashion show where every component/html elements gets its moment to shine!
|
18
|
+
|
19
|
+
6. Toss in a base style, add a pinch of variant magic, sprinkle some size adjustments and Your components/html elements are dressed to impress.
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Install the gem and add to the application's Gemfile by executing:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
bundle add classic
|
27
|
+
```
|
28
|
+
|
29
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
gem install classic
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
1. Configuration.
|
38
|
+
- `files` is location of your styles yml.
|
39
|
+
- `raise_error_on_not_found`. Default value is `false`.
|
40
|
+
If style not found then raise an error. Disable on production environment.
|
41
|
+
i.e `config.raise_error_on_not_found = Rails.env.development?`
|
42
|
+
- `auto_reload_on_change` Rails only flag will reload styles on yaml files changes.
|
43
|
+
Default value is `false`. Enable in rails development env.
|
44
|
+
i.e `config.auto_reload_on_change = !Rails.env.development?`
|
45
|
+
- `classes_merge_handler` handle custom merging of classes.
|
46
|
+
Default is `proc { |classes| classes.join(" ") }`
|
47
|
+
i.e
|
48
|
+
```ruby
|
49
|
+
tw_class_merge = TailwindMerge::Merger.new
|
50
|
+
proc { |classes| class_merge.merge(classes) }
|
51
|
+
```
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
|
55
|
+
tw_class_merge = TailwindMerge::Merger.new
|
56
|
+
|
57
|
+
Classic.configure do |config|
|
58
|
+
config.files = Dir["style/**/*.yaml"]
|
59
|
+
config.raise_error_on_not_found = true
|
60
|
+
config.auto_reload_on_change = true # For rails only.
|
61
|
+
config.classes_merge_handler = proc { |classes| tw_class_merge.merge(classes) }
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
2. How to define style using yml.
|
66
|
+
|
67
|
+
```yml
|
68
|
+
btn:
|
69
|
+
base: inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-5
|
70
|
+
varient:
|
71
|
+
default: bg-primary text-primary-foreground shadow hover:bg-primary/90
|
72
|
+
destructive: bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90
|
73
|
+
outline: border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground
|
74
|
+
secondary: bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80
|
75
|
+
ghost: hover:bg-accent hover:text-accent-foreground
|
76
|
+
link: text-primary underline-offset-4 hover:underline
|
77
|
+
size:
|
78
|
+
default: h-9 px-4 py-2
|
79
|
+
sm: h-8 rounded-md px-3 text-xs
|
80
|
+
lg: h-10 rounded-md px-8
|
81
|
+
icon: h-9 w-9
|
82
|
+
default: "(varient.default,size.default)"
|
83
|
+
|
84
|
+
card:
|
85
|
+
<self: rounded-xl border bg-card text-card-foreground shadow
|
86
|
+
header: flex flex-col space-y-1.5 p-6
|
87
|
+
title: font-semibold leading-none tracking-tight
|
88
|
+
description: text-sm text-muted-foreground
|
89
|
+
content: p-6 pt-0
|
90
|
+
footer: flex items-center p-6 pt-0
|
91
|
+
|
92
|
+
"@aliases":
|
93
|
+
btn-primary: "btn(varient.outline,size.default)"
|
94
|
+
```
|
95
|
+
|
96
|
+
3. How to use in erb, haml templates or any other templates by calling "to_cls" method on string.
|
97
|
+
|
98
|
+
* Combine options.
|
99
|
+
- `btn(varient.outline,size.lg).to_cls`
|
100
|
+
- `btn(varient.link,size.default).to_cls`
|
101
|
+
|
102
|
+
* Default style define in `default` key.
|
103
|
+
- `btn.to_cls`
|
104
|
+
|
105
|
+
* How to use alias?
|
106
|
+
- `btn-primary.to_cls`
|
107
|
+
|
108
|
+
* `<self` - Element has multiple sub component/element style key and want to use parent key as a container.
|
109
|
+
- `card.to_cls` This will use `<self` key of card.
|
110
|
+
|
111
|
+
* Add custom classes.
|
112
|
+
- `btn(varient.outline,size.lg).to_cls("mt-2 px-2")`
|
113
|
+
- `btn.to_cls("mt-2 px-2")` # it will merge classes to btn default syle
|
114
|
+
|
115
|
+
* If you are using Tailwind css then add yaml files to your tailwind config content section.
|
116
|
+
i.e
|
117
|
+
```
|
118
|
+
content: [
|
119
|
+
"./styles/*.yaml"
|
120
|
+
],
|
121
|
+
```
|
122
|
+
|
123
|
+
## Development
|
124
|
+
|
125
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
126
|
+
|
127
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
128
|
+
|
129
|
+
## Contributing
|
130
|
+
|
131
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/EloquentStudio/classic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/EloquentStudio/classic/blob/master/CODE_OF_CONDUCT.md).
|
132
|
+
|
133
|
+
## License
|
134
|
+
|
135
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
136
|
+
|
137
|
+
## Code of Conduct
|
138
|
+
|
139
|
+
Everyone interacting in the Classic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/EloquentStudio/classic/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Classic
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :files, :file_prefix, :raise_error_on_not_found, :classes_merge_handler,
|
6
|
+
:auto_reload_on_change
|
7
|
+
|
8
|
+
def validate!
|
9
|
+
if files.nil? || files.empty?
|
10
|
+
raise Classic::Error, "'files' option value is required."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
module Classic
|
7
|
+
# Store and Proces styles.
|
8
|
+
class Manager
|
9
|
+
BASE_STYLE_KEY = "base"
|
10
|
+
DEFAULT_STYLE_KEY = "default"
|
11
|
+
SELF_STYLE_KEY = "<self"
|
12
|
+
ALIASES_KEY = "@aliases"
|
13
|
+
|
14
|
+
attr_reader :config, :data, :entries, :merged_css_entries
|
15
|
+
|
16
|
+
def initialize(config:)
|
17
|
+
@config = config
|
18
|
+
@classes_merge_handler = config.classes_merge_handler
|
19
|
+
end
|
20
|
+
|
21
|
+
def files
|
22
|
+
config.files
|
23
|
+
end
|
24
|
+
|
25
|
+
def load
|
26
|
+
@data = {}
|
27
|
+
@entries = {}
|
28
|
+
@merged_css_entries = Hash.new({})
|
29
|
+
|
30
|
+
files.each do |file|
|
31
|
+
extname = File.extname(file)
|
32
|
+
file_data = (extname == "json") ? JSON.load_file(file) : YAML.load_file(file)
|
33
|
+
aliases = file_data.delete(ALIASES_KEY) if file_data.key?(ALIASES_KEY)
|
34
|
+
|
35
|
+
if config.file_prefix
|
36
|
+
prefix = File.basename(file).gsub(extname, "")
|
37
|
+
@data[prefix] = file_data
|
38
|
+
build_aliases(aliases, prefix: prefix)
|
39
|
+
else
|
40
|
+
@data.merge!(file_data) do |key, old_value, new_value|
|
41
|
+
raise Classic::Error, "dublicate value found for #{key} - values #{old_value}, #{new_value}"
|
42
|
+
end
|
43
|
+
|
44
|
+
build_aliases(aliases)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def cls(name, classes = nil)
|
50
|
+
return (@entries[name] ||= lookup(name)) unless classes
|
51
|
+
|
52
|
+
@merged_css_entries[name][classes] ||= @classes_merge_handler.call([lookup(name), classes])
|
53
|
+
end
|
54
|
+
|
55
|
+
def lookup(name)
|
56
|
+
component = @data[name] || name
|
57
|
+
|
58
|
+
component_path = if component.is_a?(String)
|
59
|
+
name
|
60
|
+
elsif component.is_a?(Hash)
|
61
|
+
# default value is style expression(i.e varient.default,size.default)) then add componet name
|
62
|
+
# (i.e btn(varient.default,size.default)))
|
63
|
+
# else add default to component name(i.e btn) with "." i.e(btn.default)
|
64
|
+
if component.key?(DEFAULT_STYLE_KEY)
|
65
|
+
if component[DEFAULT_STYLE_KEY].match?(STYLE_EXP_REGX)
|
66
|
+
"#{name}#{component[DEFAULT_STYLE_KEY]}"
|
67
|
+
else
|
68
|
+
"#{name}.#{DEFAULT_STYLE_KEY}"
|
69
|
+
end
|
70
|
+
elsif component.key?(SELF_STYLE_KEY)
|
71
|
+
"#{name}.#{SELF_STYLE_KEY}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if component_path
|
76
|
+
style_fn = parse(component_path)
|
77
|
+
classes = collect_styles(style_fn)
|
78
|
+
|
79
|
+
return style_not_found_value(name) if classes.nil? || classes.empty?
|
80
|
+
|
81
|
+
classes = classes.join(" ") if classes.is_a?(Array)
|
82
|
+
classes.strip.tr("\n", " ")
|
83
|
+
else
|
84
|
+
style_not_found_value(name)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Matches:
|
89
|
+
# btn(varient.default,size.default)
|
90
|
+
# (varient.default,size.default)
|
91
|
+
STYLE_EXP_REGX = /([\w.]*)\(([\w.,\s]*)\)/
|
92
|
+
|
93
|
+
def parse(style)
|
94
|
+
matches = style.scan(STYLE_EXP_REGX)
|
95
|
+
|
96
|
+
if matches.any?
|
97
|
+
component, options = matches.first
|
98
|
+
|
99
|
+
if component.empty?
|
100
|
+
component = options
|
101
|
+
options = ""
|
102
|
+
end
|
103
|
+
else
|
104
|
+
component = style
|
105
|
+
options = ""
|
106
|
+
end
|
107
|
+
|
108
|
+
{ component: component, options: options.split(",").map(&:strip), name: style }
|
109
|
+
end
|
110
|
+
|
111
|
+
def collect_styles(style_fn)
|
112
|
+
component = nil
|
113
|
+
|
114
|
+
style_fn[:component].split(".").each do |c|
|
115
|
+
c = c.strip
|
116
|
+
component = component ? component[c] : @data[c]
|
117
|
+
end
|
118
|
+
|
119
|
+
# If component is direct css class. i.e "flex flex-col space-y-1.5 p-6"
|
120
|
+
return style_not_found_value(style_fn[:name]) unless component
|
121
|
+
|
122
|
+
# In case of i.e "card.header" component is end result css classes.
|
123
|
+
return component if component.is_a?(String)
|
124
|
+
|
125
|
+
if style_fn[:options].empty?
|
126
|
+
# Handle "label" -> will lookup "label.<self"
|
127
|
+
return component[SELF_STYLE_KEY] if component.key?(SELF_STYLE_KEY)
|
128
|
+
|
129
|
+
# Handle "btn.size" -> will lookup "btn.size.default"
|
130
|
+
return component[DEFAULT_STYLE_KEY] if component.key?(DEFAULT_STYLE_KEY)
|
131
|
+
end
|
132
|
+
|
133
|
+
styles = []
|
134
|
+
# If component is a Hash and has 'base' entry and has style options
|
135
|
+
# i.e
|
136
|
+
# btn:
|
137
|
+
# base: rounded-md text-sm font-medium...
|
138
|
+
styles << component[BASE_STYLE_KEY] if component.key?(BASE_STYLE_KEY)
|
139
|
+
|
140
|
+
style_fn[:options].each do |o|
|
141
|
+
option = nil
|
142
|
+
|
143
|
+
o.split(".").each do |c|
|
144
|
+
c = c.strip
|
145
|
+
option = option ? option[c] : component[c]
|
146
|
+
end
|
147
|
+
|
148
|
+
if option
|
149
|
+
styles << option
|
150
|
+
else
|
151
|
+
style_not_found_value(style_fn[:name])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
styles
|
156
|
+
end
|
157
|
+
|
158
|
+
def style_not_found_value(name)
|
159
|
+
raise NotFoundError, "'#{name}' style not found." if config.raise_error_on_not_found
|
160
|
+
|
161
|
+
"#{name}-StyleNotFound"
|
162
|
+
end
|
163
|
+
|
164
|
+
def build_aliases(aliases, prefix: nil)
|
165
|
+
aliases&.each do |name, style|
|
166
|
+
if prefix
|
167
|
+
@entries["#{prefix}.#{name}"] = lookup("#{prefix}.#{style}")
|
168
|
+
else
|
169
|
+
@entries[name] = lookup(style)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Classic
|
4
|
+
# Auto loader on style files change.
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
config.after_initialize do |app|
|
7
|
+
Classic::Railtie.watch_style_files(app)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.watch_style_files(app)
|
11
|
+
style_files = Classic.object.files.map { |f| Rails.root.join(f).to_s }
|
12
|
+
reloader = app.config.file_watcher.new(style_files) {}
|
13
|
+
app.reloaders << reloader
|
14
|
+
app.reloader.to_run do
|
15
|
+
reloader.execute_if_updated { Classic.reload! }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/classic.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "classic/version"
|
4
|
+
require_relative "classic/string_ext"
|
5
|
+
require_relative "classic/configuration"
|
6
|
+
require_relative "classic/manager"
|
7
|
+
require_relative "classic/railtie" if Object.const_defined?("Rails::Railtie")
|
8
|
+
|
9
|
+
module Classic
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
class NotFoundError < StandardError; end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
config = Configuration.new
|
16
|
+
yield config
|
17
|
+
config.classes_merge_handler ||= proc { |classes| classes.join(" ") }
|
18
|
+
config.validate!
|
19
|
+
|
20
|
+
@classic = Classic::Manager.new(config: config)
|
21
|
+
@classic.load
|
22
|
+
|
23
|
+
if config.auto_reload_on_change && Object.const_defined?("Rails::Railtie")
|
24
|
+
Classic::Railtie.initializers.each(&:run)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.reload!
|
29
|
+
@classic.load
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.object
|
33
|
+
@classic
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.cls(name, classes = nil)
|
37
|
+
@classic.cls(name, classes)
|
38
|
+
end
|
39
|
+
end
|
data/sig/classic.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: classic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jiren Patel
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-01-16 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: A comprehensive utility library designed to standardize and simplify
|
13
|
+
the management of styles across web application and cache styles. This library facilitates
|
14
|
+
consistent styling, theme management and dynamically combine components styles i.e
|
15
|
+
varient,size.
|
16
|
+
email:
|
17
|
+
- jiren@eloquent.studio
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- CHANGELOG.md
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/classic.rb
|
28
|
+
- lib/classic/configuration.rb
|
29
|
+
- lib/classic/manager.rb
|
30
|
+
- lib/classic/railtie.rb
|
31
|
+
- lib/classic/string_ext.rb
|
32
|
+
- lib/classic/version.rb
|
33
|
+
- sig/classic.rbs
|
34
|
+
homepage: https://github.com/EloquentStudio/classic
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://github.com/EloquentStudio/classic
|
39
|
+
source_code_uri: https://github.com/EloquentStudio/classic
|
40
|
+
changelog_uri: https://github.com/EloquentStudio/classic
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.1.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.6.2
|
56
|
+
specification_version: 4
|
57
|
+
summary: A comprehensive utility library designed to standardize and simplify the
|
58
|
+
management of styles across web application.
|
59
|
+
test_files: []
|