tailwindcss-rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require "dry/initializer"
2
+ require "pry"
3
+ require "active_support/core_ext/object/blank"
4
+ require "active_support/core_ext/module/delegation"
5
+ require "active_support/core_ext/string/inflections"
6
+ require "active_support/core_ext/enumerable"
7
+
8
+ module Tailwindcss
9
+ class StyleAttributesToListConverter
10
+ extend Dry::Initializer
11
+
12
+ def call(**style)
13
+ add_prefix(build_style_prop_classes(style.to_h))
14
+ end
15
+
16
+ private
17
+
18
+ def add_prefix(strings)
19
+ strings.map do |style_prop_class|
20
+ [Tailwindcss.config.prefix, style_prop_class].compact_blank.join("-")
21
+ end
22
+ end
23
+
24
+ def build_style_prop_classes(style)
25
+ style.flat_map { |(style_prop, value)| classes_for_style_prop(style_prop, value) }
26
+ .compact_blank
27
+ .sort
28
+ end
29
+
30
+ def classes_for_style_prop(style_prop, value)
31
+ token = get_token(style_prop)
32
+ return build_style_prop_classes(value).map { "#{token}:#{_1}" } if style_prop.start_with?("_")
33
+ return token if value.to_s == "true"
34
+
35
+ [token, value.to_s.dasherize].compact_blank.join("-")
36
+ end
37
+
38
+ def get_token(name_or_alias)
39
+ return name_or_alias[1..] if name_or_alias.start_with?("_")
40
+
41
+ Tailwindcss.theme.to_h.find { _1 == name_or_alias || _2[:alias] == name_or_alias }.last[:token]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Tailwindcss
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,78 @@
1
+ require "dry/configurable"
2
+ require "deep_merge/rails_compat"
3
+
4
+ require "tailwindcss/version"
5
+ require "tailwindcss/constants"
6
+ require "tailwindcss/compiler/runner"
7
+
8
+ module Tailwindcss
9
+ extend Dry::Configurable
10
+ include Constants
11
+ extend self
12
+
13
+ setting :package_json_path, default: proc { "./package.json" }
14
+ setting :config_file_path, default: proc { "./tailwind.config.js" }
15
+ setting :compiler do
16
+ setting :output_path, default: proc { "./public/assets/styles.css" }
17
+ setting :compile_classes_dir, default: proc { "./tmp/tailwindcss" }
18
+ end
19
+ setting :content, default: proc { [] }
20
+ setting :prefix, default: ""
21
+
22
+ setting :tailwind_css_file_path, default: proc { Tailwindcss.config.compiler.output_path.call }
23
+ setting :tailwind_config_overrides, default: proc { {} }
24
+ setting :watch_content, default: false
25
+
26
+ setting :breakpoints, default: BREAKPOINTS
27
+ setting :pseudo_selectors, default: PSEUDO_SELECTORS
28
+ setting :pseudo_elements, default: PSEUDO_ELEMENTS
29
+
30
+ setting :theme do
31
+ THEME.each do |directive, config|
32
+ setting directive, default: proc { config }
33
+ end
34
+ setting :color_scheme, default: proc { COLOR_SCHEME }
35
+ end
36
+
37
+ setting :logger, default: proc { Logger.new(STDOUT) }
38
+
39
+ module ExtendTheme
40
+ def extend_theme(**overrides)
41
+ self.theme = theme.deeper_merge(overrides)
42
+ end
43
+ end
44
+
45
+ config.extend ExtendTheme
46
+
47
+ def theme
48
+ @theme ||= OpenStruct.new(self.config.theme.to_h.transform_values { _1.respond_to?(:call) ? _1.() : _1 })
49
+ end
50
+
51
+ def configure(&blk)
52
+ super(&blk)
53
+ init!
54
+ end
55
+
56
+ def init!
57
+ require "tailwindcss/style"
58
+ Compiler::Runner.new.call
59
+ end
60
+
61
+ def compile_css!
62
+ Tailwindcss.config.logger.call.info "Recompiling Tailwindcss..."
63
+ system "npx tailwindcss -o #{output_path} -m"
64
+ Channel.broadcast_css_changed if defined?(ActionCable)
65
+ end
66
+
67
+ def output_path
68
+ @output_path ||= Tailwindcss.config.compiler.output_path.call
69
+ end
70
+
71
+ def tailwind_css_file_path
72
+ @tailwind_css_file_path ||= Tailwindcss.config.tailwind_css_file_path.call
73
+ end
74
+
75
+ def logger
76
+ @logger ||= config.logger.call
77
+ end
78
+ end
@@ -0,0 +1,28 @@
1
+
2
+ namespace :tailwindcss do
3
+ desc "Generate TailwindCSS configuration file"
4
+ task :install do
5
+ require "tailwindcss/installer"
6
+ Tailwindcss::Installer.new.call
7
+ end
8
+
9
+ desc "Generate config file"
10
+ task :generate_config_file do
11
+ require "tailwindcss/installers/config_file_generator"
12
+ Tailwindcss::Installers::ConfigFileGenerator.new.call
13
+ end
14
+
15
+ desc "Compile TailwindCSS"
16
+ task :compile do
17
+ require "tailwindcss/compiler/runner"
18
+ Tailwindcss::Compiler::Runner.new.call
19
+ end
20
+
21
+ namespace :compile do
22
+ desc "Compile TailwindCSS and watch for file changes"
23
+ task :watch do
24
+ require "tailwindcss/compiler/runner"
25
+ Tailwindcss::Compiler::Runner.new(watch: true).call
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module Tailwindcss
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tailwindcss-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - guilherme-andrade
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: listen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: deep_merge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '7.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '7.0'
69
+ description: A Ruby wrapper for Tailwind CSS
70
+ email:
71
+ - inbox@guilherme-andrade.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".rspec"
77
+ - ".rubocop.yml"
78
+ - CHANGELOG.md
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - lib/tailwindcss.rb
86
+ - lib/tailwindcss/arbitrary_value.rb
87
+ - lib/tailwindcss/asset_helper.rb
88
+ - lib/tailwindcss/compiler/channel.rb
89
+ - lib/tailwindcss/compiler/connection.rb
90
+ - lib/tailwindcss/compiler/file_classes_extractor.rb
91
+ - lib/tailwindcss/compiler/file_parser.rb
92
+ - lib/tailwindcss/compiler/hash_args_extractor.rb
93
+ - lib/tailwindcss/compiler/output.rb
94
+ - lib/tailwindcss/compiler/runner.rb
95
+ - lib/tailwindcss/constants.rb
96
+ - lib/tailwindcss/helpers.rb
97
+ - lib/tailwindcss/installer.rb
98
+ - lib/tailwindcss/installers/config_file_generator.rb
99
+ - lib/tailwindcss/style.rb
100
+ - lib/tailwindcss/style_attributes_to_list_converter.rb
101
+ - lib/tailwindcss/version.rb
102
+ - lib/tasks/tailwindcss.rake
103
+ - sig/tailwindcss.rbs
104
+ homepage: https://guilherme-andrade.com/tailwindcss
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ homepage_uri: https://guilherme-andrade.com/tailwindcss
109
+ source_code_uri: https://github.com/guilherme-andrade/tailwindcss
110
+ changelog_uri: https://github.com/guilherme-andrade/tailwindcss/blob/main/CHANGELOG.md
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.6.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.3.7
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A Ruby wrapper for Tailwind CSS
130
+ test_files: []