tailwind_dsl 0.0.14 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c311546f3112011590192afd6386ca3e097366b4e32a7d4bdaf90eb2e50bb888
4
- data.tar.gz: c0720bf9fc432e6931772d819afebfb4e2fa2aa583bcfb36adf8fc18294f1538
3
+ metadata.gz: 5c203889b4310594acefe53d47df83e002a6b824cb29dacaeb94e79b54f31da3
4
+ data.tar.gz: 5904e14763b77cb30a64c6aab0df1bbe50dca9137c5d78b95e3b0a1a1cea1df4
5
5
  SHA512:
6
- metadata.gz: 28c7d5f434fb96350a3bac05180d9e1efc58e3172efc5a9b36c6e14e93359e88c5c3f87ecb14177c7e5a02000f1001871e1b7d388f465572b743ed5b21f7f39c
7
- data.tar.gz: 96b446cb33fbb4a976d5187f205357df2439e2699cf37c9d3b886f1734efe3661823ba255923070197155d1eff68ba0335c0af577cccad2c212e27c36bb94ccf
6
+ metadata.gz: 7afe62703ff5c4cce8f5298821df980f00c0625e9b389f393e41349a016e9c463f04cbed97c15d71826d57dde9b9b1874ec9ec8b61f1ccbb120ac748cae71e30
7
+ data.tar.gz: 1933129c10fb231930cc6ada1525dba92b2b361729965b82712b0fa7bcf4b401bb0cc8e1039e8d2e1ad4cd1551a9d2c8f0e81940c09d055d66f3e26811f99ce5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## [0.0.15](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.14...v0.0.15) (2022-10-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * refactor argument names ([3cb3a86](https://github.com/klueless-io/tailwind_dsl/commit/3cb3a869970fbe5a58afe5f1dc0cecf76b615433))
7
+
8
+ ## [0.0.14](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.13...v0.0.14) (2022-10-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * refactor sample data directories ([23e4efb](https://github.com/klueless-io/tailwind_dsl/commit/23e4efb2863643cfbc8744e656a873900a421572))
14
+ * refactor sample data directories ([4017917](https://github.com/klueless-io/tailwind_dsl/commit/401791784e51fbe771c841294a4ad837f99c8ec9))
15
+ * start working on component model extractor ([929292d](https://github.com/klueless-io/tailwind_dsl/commit/929292dcdae8d79ccd12e2eae30d3e6710bac3f2))
16
+
1
17
  ## [0.0.13](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.12...v0.0.13) (2022-10-18)
2
18
 
3
19
 
@@ -5,17 +5,22 @@ module TailwindDsl
5
5
  module ComponentModels
6
6
  # Extract component models by reading the cleansed component HTML and then using GPT3 to infer both the data/model structure.
7
7
  class Extractor
8
- attr_reader :uikit
8
+ attr_reader :components
9
9
  attr_reader :target_root_path
10
10
  attr_reader :batch_size
11
+ attr_reader :batch_left
11
12
  attr_reader :use_prompt
13
+ attr_reader :filter_design_system
14
+ attr_reader :dry_run
12
15
 
13
- def initialize(uikit, target_root_path, batch_size: 1, use_prompt: false, filter_design_system: nil)
14
- @uikit = uikit
16
+ def initialize(components, target_root_path, **args)
17
+ @components = components
15
18
  @target_root_path = target_root_path
16
- @batch_size = batch_size
19
+ @batch_size = args[:batch_size] || 1
17
20
  @batch_left = batch_size
18
- @use_prompt = use_prompt
21
+ @use_prompt = args[:use_prompt] || false
22
+ @filter_design_system = args[:filter_design_system] || nil
23
+ @dry_run = args[:dry_run] || false
19
24
  end
20
25
 
21
26
  # Goal: Extract the next (batch_size) component models using GPT3 and save them to target_root_path
@@ -28,15 +33,35 @@ module TailwindDsl
28
33
  # if :use_prompt is true then display the input/output files and ask if you wish to process the component or skip.
29
34
  # process the component by calling the GPT3 API and save the results to the target folder.
30
35
 
31
- def extract; end
36
+ def extract
37
+ filter_components.each do |component|
38
+ puts "Processing: #{component.design_system.name} -> #{component.group.key} -> #{component.name} -> remaining#: #{batch_left}"
39
+ # component_model_path = File.join(target_root_path, component.design_system.name, component.group_hierarchy, "#{component.name}.model.rb")
40
+ # next if File.exist?(component_model_path)
32
41
 
33
- # def components
34
- # @components ||= uikit.design_systems.map do |design_system|
35
- # design_system.components.map do |component|
36
- # Component.new(design_system, component, source_root_path, target_root_path)
37
- # end
38
- # end.flatten
39
- # end
42
+ # if use_prompt
43
+ # puts "Input: #{component.cleansed_html_path}"
44
+ # puts "Output: #{component_model_path}"
45
+ # puts 'Process? (y/n)'
46
+ # next unless STDIN.gets.chomp == 'y'
47
+ # end
48
+
49
+ # puts "Processing: #{component_model_path}"
50
+ @batch_left -= 1
51
+ break if batch_left.zero?
52
+
53
+ next if dry_run
54
+
55
+ # model = Gpt3::ComponentModel.new(component.cleansed_html_path)
56
+ # model.save(component_model_path)
57
+ end
58
+ end
59
+
60
+ def filter_components
61
+ return components unless filter_design_system
62
+
63
+ components.select { |component| component.design_system.name == filter_design_system }
64
+ end
40
65
  end
41
66
  end
42
67
  end
@@ -21,7 +21,9 @@ module TailwindDsl
21
21
  # .gsub(/(\n\s*\n)+/, "\n")
22
22
  attr_reader :uikit
23
23
  attr_reader :components
24
+ # Location for raw components
24
25
  attr_reader :source_root_path
26
+ # Location for component structures
25
27
  attr_reader :target_root_path
26
28
  attr_reader :reset_root_path
27
29
 
@@ -54,18 +56,19 @@ module TailwindDsl
54
56
 
55
57
  def query_components
56
58
  RawComponentQuery.query(uikit,
57
- raw_component_root_path: source_root_path,
58
- component_structure_root_path: target_root_path).records
59
+ source_root_path: source_root_path,
60
+ target_root_path: target_root_path)
61
+ .components
59
62
  end
60
63
 
61
64
  def process_components
62
65
  @components.each do |component|
63
- unless File.exist?(component.absolute_path.source_file)
64
- puts "Source file does not exist: #{component.absolute_path.source_file}"
66
+ unless File.exist?(component.absolute.source_file)
67
+ puts "Source file does not exist: #{component.absolute.source_file}"
65
68
  next
66
69
  end
67
70
 
68
- # puts "DSN: #{component.design_system.name}, GRP: #{component.group.type}, FILE: #{component.relative_path.source_file}"
71
+ # puts "DSN: #{component.design_system.name}, GRP: #{component.group.type}, FILE: #{component.relative.source_file}"
69
72
 
70
73
  process_component(component)
71
74
  end
@@ -115,23 +118,23 @@ module TailwindDsl
115
118
  # rules:
116
119
  # if the html file exists, then read the settings file, if the settings has html overwrite, then overwrite the html file
117
120
  # overwrite = true
118
- FileUtils.cp_r(component.absolute_path.source_file, component.absolute_path.target_html_file, remove_destination: true) # if overwrite
121
+ FileUtils.cp_r(component.absolute.source_file, component.absolute.target_html_file, remove_destination: true) # if overwrite
119
122
  end
120
123
 
121
124
  def create_clean_html_file(component)
122
- html = File.read(component.absolute_path.source_file) || ''
125
+ html = File.read(component.absolute.source_file) || ''
123
126
  component.captured_comment_list = html.scan(COMMENT_REGEX)
124
127
  component.captured_comment_text = component.captured_comment_list.join("\n")
125
128
 
126
129
  html = html.gsub(COMMENT_REGEX, '').gsub(BLANK_LINE_REGEX, "\n").lstrip
127
130
 
128
- File.write(component.absolute_path.target_clean_html_file, html)
131
+ File.write(component.absolute.target_clean_html_file, html)
129
132
  end
130
133
 
131
134
  def create_tailwind_config_file(component)
132
135
  component.captured_tailwind_config = extract_tailwind_config(component)
133
136
 
134
- File.write(component.absolute_path.target_tailwind_config_file, component.captured_tailwind_config) if component.captured_tailwind_config
137
+ File.write(component.absolute.target_tailwind_config_file, component.captured_tailwind_config) if component.captured_tailwind_config
135
138
  end
136
139
 
137
140
  def create_settings_file(component)
@@ -167,7 +170,7 @@ module TailwindDsl
167
170
  tailwind_config: tailwind_config_settings(component.captured_tailwind_config)
168
171
  }
169
172
 
170
- File.write(component.absolute_path.target_settings_file, JSON.pretty_generate(settings))
173
+ File.write(component.absolute.target_settings_file, JSON.pretty_generate(settings))
171
174
  end
172
175
 
173
176
  def extract_tailwind_config(component)
@@ -8,8 +8,6 @@ module TailwindDsl
8
8
  # This is a two pass process:
9
9
  # 1. Query the raw component folder for all files that match the pattern and build up a graph with required information
10
10
  # 2. Flatten the graph into a list of rows
11
- #
12
- # If you need to debug, then pass in the debug flag and it will output the graph to the console
13
11
  class RawComponentQuery
14
12
  DesignSystem = Struct.new(
15
13
  :name,
@@ -35,95 +33,101 @@ module TailwindDsl
35
33
  :target_astro_file, keyword_init: true
36
34
  )
37
35
 
38
- class Record
36
+ class Component
37
+ attr_reader :name
39
38
  attr_reader :design_system
40
39
  attr_reader :group
41
- attr_reader :absolute_path
42
- attr_reader :relative_path
40
+ attr_reader :absolute
41
+ attr_reader :relative
43
42
 
44
43
  # Storage buckets for data that is extracted from the source file
45
44
  attr_accessor :captured_comment_text
46
45
  attr_accessor :captured_comment_list
47
46
  attr_accessor :captured_tailwind_config
48
47
 
49
- def initialize(design_system:, group:, absolute_path:, relative_path:)
48
+ def initialize(name:, design_system:, group:, absolute:, relative:)
49
+ @name = name
50
50
  @design_system = design_system
51
51
  @group = group
52
- @absolute_path = absolute_path
53
- @relative_path = relative_path
52
+ @absolute = absolute
53
+ @relative = relative
54
54
  end
55
55
 
56
56
  def to_h
57
57
  {
58
+ name: name,
58
59
  design_system: design_system.to_h,
59
60
  group: group.to_h,
60
- absolute_path: absolute_path.to_h,
61
- relative_path: relative_path.to_h
61
+ absolute: absolute.to_h,
62
+ relative: relative.to_h
62
63
  }
63
64
  end
64
65
  end
65
66
 
66
67
  attr_reader :uikit
67
- attr_reader :raw_component_root_path
68
- attr_reader :component_structure_root_path
68
+ # Location for raw components
69
+ attr_reader :source_root_path
70
+ # Location for component structures
71
+ attr_reader :target_root_path
69
72
  attr_reader :current_design_system
70
- attr_reader :debug
71
- attr_reader :records
73
+ attr_reader :components
72
74
 
73
75
  def initialize(uikit, **args)
74
76
  @uikit = uikit
75
- @raw_component_root_path = args[:raw_component_root_path] || raise(ArgumentError, 'Missing raw_component_root_path')
76
- @component_structure_root_path = args[:component_structure_root_path] || raise(ArgumentError, 'Missing component_structure_root_path')
77
- @debug = args[:debug] || false
77
+ @source_root_path = args[:source_root_path] || raise(ArgumentError, 'Missing source_root_path')
78
+ @target_root_path = args[:target_root_path] || raise(ArgumentError, 'Missing target_root_path')
78
79
  end
79
80
 
80
81
  class << self
81
- def query(uikit, raw_component_root_path:, component_structure_root_path:, debug: false)
82
- instance = new(uikit, raw_component_root_path: raw_component_root_path, component_structure_root_path: component_structure_root_path, debug: debug)
82
+ def query(uikit, source_root_path:, target_root_path:)
83
+ instance = new(uikit, source_root_path: source_root_path, target_root_path: target_root_path)
83
84
  instance.call
84
85
  end
85
86
  end
86
87
 
87
88
  def call
88
- @records = build_records
89
+ @components = build_components
89
90
 
90
91
  self
91
92
  end
92
93
 
93
- # Flattened list of records in hash format
94
+ # Flattened list of components in hash format
94
95
  # @return [Array<Hash>] list
95
96
  def to_h
96
- records.map(&:to_h)
97
+ components.map(&:to_h)
97
98
  end
98
99
 
99
100
  private
100
101
 
101
- def build_records
102
+ # rubocop:disable Metrics/AbcSize
103
+ def build_components
102
104
  uikit.design_systems.flat_map do |design_system|
103
105
  @current_design_system = design_system
104
106
  design_system.groups.flat_map do |group|
105
107
  group.files.map do |file|
106
- Record.new(
108
+ Component.new(
109
+ name: file.file_name_only,
107
110
  design_system: DesignSystem.new(**map_design_system),
108
111
  group: Group.new(**map_group(group)),
109
- absolute_path: FilePath.new(**map_absolute_file(file)),
110
- relative_path: FilePath.new(**map_relative_file(file))
112
+ absolute: FilePath.new(**map_absolute_file(file)),
113
+ relative: FilePath.new(**map_relative_file(file))
111
114
  )
112
115
  end
113
116
  end
114
117
  end
115
118
  end
119
+ # rubocop:enable Metrics/AbcSize
116
120
 
117
121
  def design_system_name
118
122
  current_design_system.name
119
123
  end
120
124
 
121
125
  def source_path
122
- File.join(raw_component_root_path, design_system_name)
126
+ File.join(source_root_path, design_system_name)
123
127
  end
124
128
 
125
129
  def target_path
126
- File.join(component_structure_root_path, design_system_name)
130
+ File.join(target_root_path, design_system_name)
127
131
  end
128
132
 
129
133
  def map_design_system
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindDsl
4
- VERSION = '0.0.14'
4
+ VERSION = '0.0.16'
5
5
  end
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tailwind_dsl",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "tailwind_dsl",
9
- "version": "0.0.14",
9
+ "version": "0.0.16",
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.14",
3
+ "version": "0.0.16",
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailwind_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdlet