tailwind_ui 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.vscode/settings.json +6 -0
- data/README.md +12 -10
- data/Rakefile +2 -4
- data/exe/jsx_to_erb +8 -0
- data/lib/tailwind_ui/jsx_to_erb.rb +124 -0
- data/lib/tailwind_ui/version.rb +1 -1
- metadata +9 -9
- data/.rubocop.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e4997c80b6251a4c702f08d220cdc8fa147c3455c06c9cd57ddabb2974a56f9
|
4
|
+
data.tar.gz: e029cb0d11008291b4e66c4665930d25cdf7284821924acb72fd76a5e0232f5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f7a781875243af0ea6103ad94819a9c930fc4d4e0cfa5e3ccb8afe3c905871ef8c6a0eae3fa55ebf6488b573161dcdd3cd4a062af95b94f1e0a99d1688204a
|
7
|
+
data.tar.gz: 026e78bdc383918a1a08ef231fd79a32552eb23d68983eb26733660401a86ce720a5800dee419ffbc827445b7bf123116ac5b2eac001edcbeffa331f655826eb
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.4.1
|
data/README.md
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
#
|
1
|
+
# tailwind_ui
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tailwind_ui`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
This gem is for working with [Tailwind UI](https://tailwindui.com).
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
7
|
Install the gem and add to the application's Gemfile by executing:
|
12
8
|
|
13
|
-
$ bundle add
|
9
|
+
$ bundle add tailwind_ui
|
14
10
|
|
15
11
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
12
|
|
17
|
-
$ gem install
|
13
|
+
$ gem install tailwind_ui
|
18
14
|
|
19
15
|
## Usage
|
20
16
|
|
21
|
-
|
17
|
+
First, copy the React (JSX) code from [Tailwind UI](https://tailwindui.com) to a local file.
|
18
|
+
|
19
|
+
Then use the `jsx_to_erb` command to convert it to ERB, for example:
|
20
|
+
|
21
|
+
`bundle exec jsx_to_erb simple.jsx > app/views/_simple.html.erb`
|
22
|
+
|
23
|
+
Only some basic components are currently supported. The plan is to gradually increase the coverage.
|
22
24
|
|
23
25
|
## Development
|
24
26
|
|
@@ -28,7 +30,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
28
30
|
|
29
31
|
## Contributing
|
30
32
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/andyw8/tailwind_ui.
|
32
34
|
|
33
35
|
## License
|
34
36
|
|
data/Rakefile
CHANGED
data/exe/jsx_to_erb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
module TailwindUi
|
5
|
+
class Error < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
class NotYetSupported < TailwindUi::Error
|
9
|
+
end
|
10
|
+
|
11
|
+
class UnconvertedBraces < TailwindUi::Error
|
12
|
+
end
|
13
|
+
|
14
|
+
class ClipPathNotYetSupported < TailwindUi::Error
|
15
|
+
end
|
16
|
+
|
17
|
+
class Special < TailwindUi::Error
|
18
|
+
end
|
19
|
+
|
20
|
+
class JsxToErb
|
21
|
+
def self.from_path(path)
|
22
|
+
file_contents = File.read(path)
|
23
|
+
new(file_contents)
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(file_contents)
|
27
|
+
if file_contents.include?("This example requires updating your template")
|
28
|
+
raise Special
|
29
|
+
end
|
30
|
+
|
31
|
+
unless file_contents.lines.first.start_with?("export default function")
|
32
|
+
raise NotYetSupported
|
33
|
+
end
|
34
|
+
|
35
|
+
if file_contents.include?("clipPath")
|
36
|
+
raise ClipPathNotYetSupported
|
37
|
+
end
|
38
|
+
|
39
|
+
@file_contents = file_contents
|
40
|
+
end
|
41
|
+
|
42
|
+
def full
|
43
|
+
tags = @file_contents.match(/(?<tags> *<.*>)/m)[:tags]
|
44
|
+
result = without_indentation(tags)
|
45
|
+
result = handle_style_attributes(result)
|
46
|
+
result = with_jsx_keywords_updated(result)
|
47
|
+
result = convert_camelcase_attributes(result)
|
48
|
+
check_for_missed_camel_case_tags!(result)
|
49
|
+
result = handle_jsx_comments(result)
|
50
|
+
result = handle_brace_attributes(result)
|
51
|
+
result = handle_inner_braces(result)
|
52
|
+
raise UnconvertedBraces if result.include?("{") || result.include?("}")
|
53
|
+
|
54
|
+
# Parse the ERB to ensure it's valid
|
55
|
+
ERB.new(result).result
|
56
|
+
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def convert_camelcase_attributes(markup)
|
63
|
+
result = markup
|
64
|
+
{
|
65
|
+
autoComplete: "autocomplete",
|
66
|
+
dateTime: "datetime",
|
67
|
+
defaultValue: "value",
|
68
|
+
fillOpacity: "fill-opacity",
|
69
|
+
gradientUnits: "gradient-units",
|
70
|
+
preserveAspectRatio: "preserve-aspect-ratio",
|
71
|
+
stopColor: "stop-color",
|
72
|
+
viewBox: "view-box"
|
73
|
+
}.each do |(camel_case, normal)|
|
74
|
+
result = result.gsub(camel_case.to_s, normal)
|
75
|
+
end
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
CAMEL_CASE = /^[a-zA-Z]+([A-Z][a-z]+)+$/
|
80
|
+
|
81
|
+
def check_for_missed_camel_case_tags!(str)
|
82
|
+
# Need to specify XML here to avoid Nokgiri downcasing automatically
|
83
|
+
doc = Nokogiri::XML.fragment(str)
|
84
|
+
|
85
|
+
doc.traverse do |node|
|
86
|
+
node.attributes.each do |name, value|
|
87
|
+
raise TailwindUi::Error, "found camelcase: #{name}" if name.match?(CAMEL_CASE)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def handle_jsx_comments(markup)
|
93
|
+
markup
|
94
|
+
.gsub("{/*", "<%#")
|
95
|
+
.gsub("*/}", "%>")
|
96
|
+
end
|
97
|
+
|
98
|
+
def handle_brace_attributes(markup)
|
99
|
+
markup
|
100
|
+
.gsub(/(\w+)=\{(\d+)}/m, '\1="\2"')
|
101
|
+
end
|
102
|
+
|
103
|
+
def handle_style_attributes(markup)
|
104
|
+
markup.gsub(/style={{ (.*) }}/, 'style="\1"')
|
105
|
+
end
|
106
|
+
|
107
|
+
def handle_inner_braces(markup)
|
108
|
+
markup.gsub("{", "<%= ").gsub("}", " %>")
|
109
|
+
end
|
110
|
+
|
111
|
+
def with_jsx_keywords_updated(markup)
|
112
|
+
markup
|
113
|
+
.gsub(/className="([^"]+)"/, 'class="\1"')
|
114
|
+
.gsub(/htmlFor="([^"]+)"/, 'for="\1"')
|
115
|
+
end
|
116
|
+
|
117
|
+
def without_indentation(tags)
|
118
|
+
indentation_level = tags.index("<")
|
119
|
+
tags.lines.map do |line|
|
120
|
+
line[indentation_level..]
|
121
|
+
end.join + "\n"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/lib/tailwind_ui/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailwind_ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Waite
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
10
|
+
date: 2024-12-29 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: nokogiri
|
@@ -24,19 +23,22 @@ dependencies:
|
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '1.17'
|
27
|
-
description:
|
28
26
|
email:
|
29
27
|
- 13400+andyw8@users.noreply.github.com
|
30
|
-
executables:
|
28
|
+
executables:
|
29
|
+
- jsx_to_erb
|
31
30
|
extensions: []
|
32
31
|
extra_rdoc_files: []
|
33
32
|
files:
|
34
|
-
- ".
|
33
|
+
- ".ruby-version"
|
34
|
+
- ".vscode/settings.json"
|
35
35
|
- CHANGELOG.md
|
36
36
|
- LICENSE.txt
|
37
37
|
- README.md
|
38
38
|
- Rakefile
|
39
|
+
- exe/jsx_to_erb
|
39
40
|
- lib/tailwind_ui.rb
|
41
|
+
- lib/tailwind_ui/jsx_to_erb.rb
|
40
42
|
- lib/tailwind_ui/version.rb
|
41
43
|
- sig/tailwind_ui.rbs
|
42
44
|
homepage: https://github.com/andyw8/tailwind_ui
|
@@ -46,7 +48,6 @@ metadata:
|
|
46
48
|
allowed_push_host: https://rubygems.org
|
47
49
|
homepage_uri: https://github.com/andyw8/tailwind_ui
|
48
50
|
source_code_uri: https://github.com/andyw8/tailwind_ui
|
49
|
-
post_install_message:
|
50
51
|
rdoc_options: []
|
51
52
|
require_paths:
|
52
53
|
- lib
|
@@ -61,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
62
|
- !ruby/object:Gem::Version
|
62
63
|
version: '0'
|
63
64
|
requirements: []
|
64
|
-
rubygems_version: 3.
|
65
|
-
signing_key:
|
65
|
+
rubygems_version: 3.6.2
|
66
66
|
specification_version: 4
|
67
67
|
summary: Tools for working with Tailwind UI
|
68
68
|
test_files: []
|