tailwind_dsl 0.0.11 → 0.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68a690ad2b3e6e2052376543026bd62cd78c42e1d1c1b66fdbb8c4aee6b714ee
4
- data.tar.gz: 42774c4d3629197a4352150e7f7843c5338488bcc6387495fec7ce4b419efbbf
3
+ metadata.gz: 707385386be771dc2457c12377c7522b367fd3dc4fe806136d49f0ee0b3df12a
4
+ data.tar.gz: 1e79a6487b05453ae75d7b6c5bc68d43371e4068c4b8a2e18182a2353f587989
5
5
  SHA512:
6
- metadata.gz: 3de3cc5f53383542f91b779de83fe6b6eb7737d559243230357345485c385344a31fae4d85ec30b660c8d255256a0b8de87b31983dd589704558411cc379c55c
7
- data.tar.gz: 775e8d304ad2c414cb6ba31072e44459e5929233a6878a1c579d9fc8a5365895281d0fe04f13bc7fc0f48f197bac11221584a9aaa69ab4387a2dd6c35d76d8ec
6
+ metadata.gz: 3295d19615b011bb2b44ef7bb983d3e921723224992c72e07e8cb702086cade1d5b6fe9e4eeb67e30c987b523a2a82a1772d8bbb9bd9f1145685a6059a0eca07
7
+ data.tar.gz: 233c7879ba2613c8ebf6530793ee4a326e53731c4c3dd3f50061407b3e19b4bae35441c4124837343aed1b20acb1bb872e4e8f06d3b45be144842e44fabbc75d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.0.11](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.10...v0.0.11) (2022-10-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add raw component query object for use by component structures ([16cc578](https://github.com/klueless-io/tailwind_dsl/commit/16cc5785ee118b31d90c62e38b88a7ddae9c342f))
7
+
1
8
  ## [0.0.10](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.9...v0.0.10) (2022-10-13)
2
9
 
3
10
 
@@ -20,73 +20,71 @@ module TailwindDsl
20
20
 
21
21
  # .gsub(/(\n\s*\n)+/, "\n")
22
22
  attr_reader :uikit
23
- attr_reader :root_raw_component_path
24
- attr_reader :root_target_path
23
+ attr_reader :source_root_path
24
+ attr_reader :target_root_path
25
25
  attr_reader :reset_root_path
26
26
 
27
- def initialize(uikit, root_raw_component_path, root_target_path, reset_root_path: false)
27
+ def initialize(uikit, source_root_path, target_root_path, reset_root_path: false)
28
28
  @uikit = uikit
29
- @root_raw_component_path = root_raw_component_path
30
- @root_target_path = root_target_path
29
+ @source_root_path = source_root_path
30
+ @target_root_path = target_root_path
31
31
  @reset_root_path = reset_root_path
32
32
  end
33
33
 
34
34
  def generate
35
- assert_root_target_path_exists
35
+ assert_target_root_path_exists
36
36
 
37
37
  delete_target_root_path if reset_root_path
38
38
 
39
- uikit.design_systems.each do |design_system|
40
- process_design_system(design_system)
41
- end
39
+ @components = query_components
40
+
41
+ process_components
42
42
  end
43
43
 
44
44
  private
45
45
 
46
- def assert_root_target_path_exists
47
- raise 'Target path does not exist' unless Dir.exist?(root_target_path)
46
+ def assert_target_root_path_exists
47
+ raise 'Target path does not exist' unless Dir.exist?(target_root_path)
48
48
  end
49
49
 
50
50
  def delete_target_root_path
51
- FileUtils.rm_rf(Dir.glob("#{root_target_path}/*"))
51
+ FileUtils.rm_rf(Dir.glob("#{target_root_path}/*"))
52
52
  end
53
53
 
54
- def process_design_system(design_system)
55
- design_system_name = design_system.name
56
- design_system.groups.each do |group|
57
- process_group(design_system_name, group)
58
- end
54
+ def query_components
55
+ RawComponentQuery.query(uikit,
56
+ raw_component_root_path: source_root_path,
57
+ component_structure_root_path: target_root_path).records
59
58
  end
60
59
 
61
- def process_group(design_system_name, group)
62
- group.files.each do |file|
63
- # puts "DSN: #{design_system_name}, GRP: #{group.type}, FILE: #{file.file}"
64
- data = Data.new(design_system_name, group, file, root_raw_component_path)
65
-
66
- unless data.source.exist?
67
- puts "Source file does not exist: #{data.source.file}"
60
+ def process_components
61
+ @components.each do |component|
62
+ unless File.exist?(component.absolute_path.source_file)
63
+ puts "Source file does not exist: #{component.absolute_path.source_file}"
68
64
  next
69
65
  end
70
66
 
71
- process_component(data)
67
+ # puts "DSN: #{component.design_system.name}, GRP: #{component.group.type}, FILE: #{component.relative_path.source_file}"
68
+
69
+ process_component(component)
72
70
  end
73
71
  end
74
72
 
75
- def process_component(data)
73
+ def process_component(component)
76
74
  # Create a folder for the component
77
- make_target_folder(data)
75
+ make_target_folder(component)
78
76
 
79
- # Create a HTML file for each component
80
- create_html_file(data)
77
+ # # Create a HTML file for each component
78
+ create_html_file(component)
81
79
 
82
- # Create a clean HTML file for each component (comments removed)
83
- create_clean_html_file(data)
80
+ # # Create a clean HTML file for each component (comments removed)
81
+ create_clean_html_file(component)
84
82
 
85
- # Create a tailwind config file (if one exists) - look in first comment for the ``` ```
86
- create_tailwind_config_file(data)
83
+ # # Create a tailwind config file (if one exists) - look in first comment for the ``` ```
84
+ create_tailwind_config_file(component)
87
85
 
88
- # Create a settings file after extracting information from the HTML file
89
- create_settings_file(data)
86
+ # # Create a settings file after extracting information from the HTML file
87
+ create_settings_file(component)
90
88
 
91
89
  # Build a menu of sources
92
90
  # see: https://tailwindui.com/components/application-ui/data-display/description-lists
@@ -104,42 +102,38 @@ module TailwindDsl
104
102
  # Note that the data file is meant to represent the data in the raw component
105
103
  # Write an Astro file
106
104
 
107
- def target_path(data)
108
- File.join(root_target_path, data.design_system_name, data.target.folder)
109
- end
110
-
111
- def target_file(data, file)
112
- File.join(root_target_path, data.design_system_name, file)
105
+ def target_path(component)
106
+ File.join(target_root_path, component.design_system.name, component.group.folder)
113
107
  end
114
108
 
115
- def make_target_folder(data)
116
- FileUtils.mkdir_p(target_path(data))
109
+ def make_target_folder(component)
110
+ FileUtils.mkdir_p(target_path(component))
117
111
  end
118
112
 
119
- def create_html_file(data)
113
+ def create_html_file(component)
120
114
  # rules:
121
115
  # if the html file exists, then read the settings file, if the settings has html overwrite, then overwrite the html file
122
116
  # overwrite = true
123
- FileUtils.cp_r(data.source.file, target_file(data, data.target.html_file), remove_destination: true) # if overwrite
117
+ FileUtils.cp_r(component.absolute_path.source_file, component.absolute_path.target_html_file, remove_destination: true) # if overwrite
124
118
  end
125
119
 
126
- def create_clean_html_file(data)
127
- html = data.source.content || ''
128
- data.captured_comment_list = html.scan(COMMENT_REGEX)
129
- data.captured_comment_text = data.captured_comment_list.join("\n")
120
+ def create_clean_html_file(component)
121
+ html = File.read(component.absolute_path.source_file) || ''
122
+ component.captured_comment_list = html.scan(COMMENT_REGEX)
123
+ component.captured_comment_text = component.captured_comment_list.join("\n")
130
124
 
131
125
  html = html.gsub(COMMENT_REGEX, '').gsub(BLANK_LINE_REGEX, "\n").lstrip
132
126
 
133
- File.write(target_file(data, data.target.clean_html_file), html)
127
+ File.write(component.absolute_path.target_clean_html_file, html)
134
128
  end
135
129
 
136
- def create_tailwind_config_file(data)
137
- data.captured_tailwind_config = extract_tailwind_config(data)
130
+ def create_tailwind_config_file(component)
131
+ component.captured_tailwind_config = extract_tailwind_config(component)
138
132
 
139
- File.write(target_file(data, data.target.tailwind_config_file), data.captured_tailwind_config) if data.captured_tailwind_config
133
+ File.write(component.absolute_path.target_tailwind_config_file, component.captured_tailwind_config) if component.captured_tailwind_config
140
134
  end
141
135
 
142
- def create_settings_file(data)
136
+ def create_settings_file(component)
143
137
  # CUSTOM
144
138
  # templates/tailwind/tui/ecommerce/page/product-pages/02.html
145
139
  # templates/tailwind/tui/ecommerce/components/product-overviews/04.html
@@ -164,31 +158,31 @@ module TailwindDsl
164
158
  # templates/tailwind/tui/application-ui/page/home-screens/02.html
165
159
  # templates/tailwind/tui/application-ui/component/list/feed/03.html
166
160
  settings = {
167
- source: extract_source(data),
161
+ source: extract_source(component),
168
162
  custom_html: {
169
- html: data.captured_comment_text.match(/<html.*>/),
170
- body: data.captured_comment_text.match(/<body.*>/)
163
+ html: component.captured_comment_text.match(/<html.*>/),
164
+ body: component.captured_comment_text.match(/<body.*>/)
171
165
  },
172
- tailwind_config: tailwind_config_settings(data.captured_tailwind_config)
166
+ tailwind_config: tailwind_config_settings(component.captured_tailwind_config)
173
167
  }
174
168
 
175
- File.write(target_file(data, data.target.settings_file), JSON.pretty_generate(settings))
169
+ File.write(component.absolute_path.target_settings_file, JSON.pretty_generate(settings))
176
170
  end
177
171
 
178
- def extract_tailwind_config(data)
179
- return nil if data.captured_comment_list.length.zero? || !data.captured_comment_list.first.include?('// tailwind.config.js')
172
+ def extract_tailwind_config(component)
173
+ return nil if component.captured_comment_list.length.zero? || !component.captured_comment_list.first.include?('// tailwind.config.js')
180
174
 
181
- data.captured_comment_list.first.match(TAILWIND_CONFIG_REGEX)[:tailwind]
175
+ component.captured_comment_list.first.match(TAILWIND_CONFIG_REGEX)[:tailwind]
182
176
  end
183
177
 
184
- def extract_source(data)
178
+ def extract_source(component)
185
179
  # In future I may be able to store the source in a comment in the HTML file
186
180
  # but at the moment all components are generally from TailwindUI and the source
187
181
  # URL can be inferred from the sub keys.
188
182
 
189
- return "https://tailwindui.com/components/#{data.group.sub_keys.join('/')}" if data.design_system_name == 'tui'
183
+ return "https://tailwindui.com/components/#{component.group.sub_keys.join('/')}" if component.design_system.name == 'tui'
190
184
 
191
- "##{data.design_system_name}/#{data.group.sub_keys.join('/')}"
185
+ "##{component.design_system.name}/#{component.group.sub_keys.join('/')}"
192
186
  end
193
187
 
194
188
  def tailwind_config_settings(raw_tailwind_config)
@@ -18,14 +18,14 @@ module TailwindDsl
18
18
  keyword_init: true
19
19
  )
20
20
 
21
- ComponentGroup = Struct.new(
21
+ Group = Struct.new(
22
22
  :key,
23
23
  :type,
24
24
  :sub_keys,
25
25
  :folder,
26
26
  keyword_init: true
27
27
  )
28
- ComponentInfo = Struct.new(
28
+ FilePath = Struct.new(
29
29
  :source_file,
30
30
  :target_html_file,
31
31
  :target_clean_html_file,
@@ -37,23 +37,28 @@ module TailwindDsl
37
37
 
38
38
  class Record
39
39
  attr_reader :design_system
40
- attr_reader :component_group
41
- attr_reader :absolute_component
42
- attr_reader :relative_component
40
+ attr_reader :group
41
+ attr_reader :absolute_path
42
+ attr_reader :relative_path
43
43
 
44
- def initialize(design_system:, component_group:, absolute_component:, relative_component:)
44
+ # Storage buckets for data that is extracted from the source file
45
+ attr_accessor :captured_comment_text
46
+ attr_accessor :captured_comment_list
47
+ attr_accessor :captured_tailwind_config
48
+
49
+ def initialize(design_system:, group:, absolute_path:, relative_path:)
45
50
  @design_system = design_system
46
- @component_group = component_group
47
- @absolute_component = absolute_component
48
- @relative_component = relative_component
51
+ @group = group
52
+ @absolute_path = absolute_path
53
+ @relative_path = relative_path
49
54
  end
50
55
 
51
56
  def to_h
52
57
  {
53
58
  design_system: design_system.to_h,
54
- component_group: component_group.to_h,
55
- absolute_component: absolute_component.to_h,
56
- relative_component: relative_component.to_h
59
+ group: group.to_h,
60
+ absolute_path: absolute_path.to_h,
61
+ relative_path: relative_path.to_h
57
62
  }
58
63
  end
59
64
  end
@@ -63,6 +68,7 @@ module TailwindDsl
63
68
  attr_reader :component_structure_root_path
64
69
  attr_reader :current_design_system
65
70
  attr_reader :debug
71
+ attr_reader :records
66
72
 
67
73
  def initialize(uikit, **args)
68
74
  @uikit = uikit
@@ -79,53 +85,52 @@ module TailwindDsl
79
85
  end
80
86
 
81
87
  def call
82
- run_query
83
- # puts JSON.pretty_generate(graph) if debug
84
- # {
85
- # list: list.map(&:to_h)
86
- # }
88
+ @records = build_records
89
+
87
90
  self
88
91
  end
89
92
 
90
93
  # Flattened list of records in hash format
91
94
  # @return [Array<Hash>] list
92
95
  def to_h
93
- @list.map(&:to_h)
96
+ records.map(&:to_h)
94
97
  end
95
98
 
96
- # Flattened list of records
97
- #
98
- # @return [Array<Record>] list
99
- def records
100
- @list
101
- end
99
+ private
102
100
 
103
- # Graph hierarchy is kept in deep nested format
104
- #
105
- # @return [Array<Hash>] graph
106
- def graph
107
- return @graph if defined? @graph
101
+ def build_records
102
+ uikit.design_systems.flat_map do |design_system|
103
+ @current_design_system = design_system
104
+ design_system.groups.flat_map do |group|
105
+ group.files.map do |file|
106
+ Record.new(
107
+ design_system: DesignSystem.new(**map_design_system),
108
+ group: Group.new(**map_group(group)),
109
+ absolute_path: FilePath.new(**map_absolute_file(file)),
110
+ relative_path: FilePath.new(**map_relative_file(file))
111
+ )
112
+ end
113
+ end
114
+ end
115
+ end
108
116
 
109
- @graph = build_graph
117
+ def design_system_name
118
+ current_design_system.name
110
119
  end
111
120
 
112
- private
121
+ def source_path
122
+ File.join(raw_component_root_path, design_system_name)
123
+ end
113
124
 
114
- def build_graph
115
- uikit.design_systems.map do |design_system|
116
- @current_design_system = design_system
117
- map_design_system
118
- end
125
+ def target_path
126
+ File.join(component_structure_root_path, design_system_name)
119
127
  end
120
128
 
121
129
  def map_design_system
122
130
  {
123
- name: current_design_system.name,
131
+ name: design_system_name,
124
132
  source_path: source_path,
125
- target_path: target_path,
126
- groups: current_design_system.groups.map do |group|
127
- map_group(group)
128
- end
133
+ target_path: target_path
129
134
  }
130
135
  end
131
136
 
@@ -134,63 +139,35 @@ module TailwindDsl
134
139
  key: group.key,
135
140
  type: group.type,
136
141
  sub_keys: group.sub_keys,
137
- files: group.files.map do |file|
138
- map_file(file)
139
- end
142
+ folder: group.folder
140
143
  }
141
144
  end
142
145
 
143
- # rubocop:disable Metrics/AbcSize
144
- def map_file(file)
146
+ def map_relative_file(file)
145
147
  {
146
- relative: {
147
- source_file: file.file,
148
- target_html_file: file.target.html_file,
149
- target_clean_html_file: file.target.clean_html_file,
150
- target_tailwind_config_file: file.target.tailwind_config_file,
151
- target_settings_file: file.target.settings_file,
152
- target_data_file: file.target.data_file,
153
- target_astro_file: file.target.astro_file
154
- },
155
- absolute: {
156
- source_file: File.join(source_path, file.file),
157
- target_html_file: File.join(target_path, file.target.html_file),
158
- target_clean_html_file: File.join(target_path, file.target.clean_html_file),
159
- target_tailwind_config_file: File.join(target_path, file.target.tailwind_config_file),
160
- target_settings_file: File.join(target_path, file.target.settings_file),
161
- target_data_file: File.join(target_path, file.target.data_file),
162
- target_astro_file: File.join(target_path, file.target.astro_file)
163
- }
148
+ source_file: file.file,
149
+ target_html_file: file.target.html_file,
150
+ target_clean_html_file: file.target.clean_html_file,
151
+ target_tailwind_config_file: file.target.tailwind_config_file,
152
+ target_settings_file: file.target.settings_file,
153
+ target_data_file: file.target.data_file,
154
+ target_astro_file: file.target.astro_file
164
155
  }
165
156
  end
166
- # rubocop:enable Metrics/AbcSize
167
-
168
- def design_system_name
169
- current_design_system.name
170
- end
171
157
 
172
- def source_path
173
- File.join(raw_component_root_path, current_design_system.name)
174
- end
175
-
176
- def target_path
177
- File.join(component_structure_root_path, current_design_system.name)
178
- end
179
-
180
- def run_query
181
- @list = graph.flat_map do |design_system|
182
- design_system[:groups].flat_map do |group|
183
- group[:files].map do |file|
184
- Record.new(
185
- design_system: DesignSystem.new(**design_system.slice(:name, :source_path, :target_path)),
186
- component_group: ComponentGroup.new(**group.slice(:key, :type, :sub_keys)),
187
- absolute_component: ComponentInfo.new(**file[:absolute]),
188
- relative_component: ComponentInfo.new(**file[:relative])
189
- )
190
- end
191
- end
192
- end
158
+ # rubocop:disable Metrics/AbcSize
159
+ def map_absolute_file(file)
160
+ {
161
+ source_file: File.join(source_path, file.file),
162
+ target_html_file: File.join(target_path, file.target.html_file),
163
+ target_clean_html_file: File.join(target_path, file.target.clean_html_file),
164
+ target_tailwind_config_file: File.join(target_path, file.target.tailwind_config_file),
165
+ target_settings_file: File.join(target_path, file.target.settings_file),
166
+ target_data_file: File.join(target_path, file.target.data_file),
167
+ target_astro_file: File.join(target_path, file.target.astro_file)
168
+ }
193
169
  end
170
+ # rubocop:enable Metrics/AbcSize
194
171
  end
195
172
  end
196
173
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindDsl
4
- VERSION = '0.0.11'
4
+ VERSION = '0.0.12'
5
5
  end
data/lib/tailwind_dsl.rb CHANGED
@@ -15,7 +15,6 @@ require_relative 'tailwind_dsl/etl/raw_components/schema/group'
15
15
  require_relative 'tailwind_dsl/etl/raw_components/schema/design_system'
16
16
  require_relative 'tailwind_dsl/etl/raw_components/schema/uikit'
17
17
 
18
- require_relative 'tailwind_dsl/etl/component_structures/data'
19
18
  require_relative 'tailwind_dsl/etl/component_structures/raw_component_query'
20
19
  require_relative 'tailwind_dsl/etl/component_structures/generator'
21
20
  # require_relative 'tailwind_dsl/astro_demo/generate_astro_page_data'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tailwind_dsl",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "tailwind_dsl",
9
- "version": "0.0.11",
9
+ "version": "0.0.12",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.1",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind_dsl",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Tailwind DSL will build tailwind websites useing Domain Specific Language conventions",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailwind_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
@@ -2151,7 +2151,6 @@ files:
2151
2151
  - lib/_.rb
2152
2152
  - lib/tailwind_dsl.rb
2153
2153
  - lib/tailwind_dsl/astro_demo/generate_astro_page_data.rb
2154
- - lib/tailwind_dsl/etl/component_structures/data.rb
2155
2154
  - lib/tailwind_dsl/etl/component_structures/generator.rb
2156
2155
  - lib/tailwind_dsl/etl/component_structures/raw_component_query.rb
2157
2156
  - lib/tailwind_dsl/etl/element.rb
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TailwindDsl
4
- module Etl
5
- module ComponentStructures
6
- # -----------------------------------------------------------------------------------------------
7
- # Internal Data Structure
8
- class Data
9
- attr_reader :design_system_name
10
- attr_reader :group # Component group information
11
- attr_reader :source # Source file information for the component
12
- attr_reader :target # Multiple target file information
13
-
14
- # Storage buckets for data that is extracted from the source file
15
- attr_accessor :captured_comment_text
16
- attr_accessor :captured_comment_list
17
- attr_accessor :captured_tailwind_config
18
-
19
- # rubocop:disable Metrics/AbcSize
20
- def initialize(design_system_name, group, file, root_raw_component_path)
21
- @design_system_name = design_system_name
22
-
23
- @captured_comment_text = ''
24
- @captured_comment_list = []
25
- @captured_tailwind_config = ''
26
-
27
- @group = Group.new(key: group.key, type: group.type, sub_keys: group.sub_keys)
28
- @source = Source.new(file: File.join(root_raw_component_path, design_system_name, file.file))
29
- @target = Target.new(
30
- folder: group.folder,
31
- html_file: file.target.html_file,
32
- clean_html_file: file.target.clean_html_file,
33
- tailwind_config_file: file.target.tailwind_config_file,
34
- settings_file: file.target.settings_file,
35
- data_file: file.target.data_file,
36
- astro_file: file.target.astro_file
37
- )
38
- end
39
- # rubocop:enable Metrics/AbcSize
40
-
41
- Group = Struct.new(:key, :type, :sub_keys, keyword_init: true)
42
- Source = Struct.new(:file, keyword_init: true) do
43
- def exist?
44
- File.exist?(file)
45
- end
46
-
47
- def content
48
- @content ||= File.exist?(file) ? File.read(file) : ''
49
- end
50
- end
51
- Target = Struct.new(:folder, :html_file, :clean_html_file, :tailwind_config_file, :settings_file, :data_file, :astro_file, keyword_init: true)
52
- end
53
- end
54
- end
55
- end