tailwind_dsl 0.0.6 → 0.0.7

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: d70d1c6b80a54a13b64938342e2c3cf307e790ca874362c2eb6ab7ab3767f993
4
- data.tar.gz: b4263d93baa86a44c06d82cc3b63657226b7641404e031820935972d24a830de
3
+ metadata.gz: 12b4cb1ead96f5fff7c3314de7a9c1cbf0acc4543749a16bd11ad1044f54c3bb
4
+ data.tar.gz: afc589fd9df719bf67b6ab61088dd65345d39b617af6a5924f0a07a027991661
5
5
  SHA512:
6
- metadata.gz: a5033848253350e250c5ebd0d606b20512885fb27fc4e7a088bb81509b8ffb3dff93ccb75e1433b9fec0bfbb76ea3bb0b2ea3e2a2326f4544d6cdb7797781a9c
7
- data.tar.gz: ce6f34ad77eb7c1f825cd7bb3047ce7f8bfec19ba86570abbc602c3c33cf04d083bf92246b99f1bfc4c729c35a5d3ae7cb150b6ab7748a3a6ff8cffe2d695f9e
6
+ metadata.gz: a88b93f3410119b8af4521b75fea20af52dfa84bae7b617ca163cfd3a600eeb36ff534ae470b2a99db4307313815657f05426618b3fbf32c08ba2b3d21658761
7
+ data.tar.gz: b4bf2cc19b04b6ff284cfeba11c152921c869c989f53cb1efcca20aa2a3e71de84d08a544c7709512dd5bcd44a9d72c2e2470900d5e940c988dd58676654e403
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.0.6](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.5...v0.0.6) (2022-10-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add tests for generating component structures ([1299d63](https://github.com/klueless-io/tailwind_dsl/commit/1299d6341c680a21c9fd2dbbcfd7422e5ceab443))
7
+
1
8
  ## [0.0.5](https://github.com/klueless-io/tailwind_dsl/compare/v0.0.4...v0.0.5) (2022-10-12)
2
9
 
3
10
 
@@ -17,7 +17,7 @@ module TailwindDsl
17
17
  attr_accessor :captured_tailwind_config
18
18
 
19
19
  # rubocop:disable Metrics/AbcSize
20
- def initialize(design_system_name, group, file)
20
+ def initialize(design_system_name, group, file, root_raw_component_path)
21
21
  @design_system_name = design_system_name
22
22
 
23
23
  @captured_comment_text = ''
@@ -25,7 +25,7 @@ module TailwindDsl
25
25
  @captured_tailwind_config = ''
26
26
 
27
27
  @group = Group.new(key: group.key, type: group.type, sub_keys: group.sub_keys)
28
- @source = Source.new(file: file.absolute_file)
28
+ @source = Source.new(file: File.join(root_raw_component_path, design_system_name, file.file))
29
29
  @target = Target.new(
30
30
  folder: group.folder,
31
31
  html_file: file.target.html_file,
@@ -20,11 +20,13 @@ module TailwindDsl
20
20
 
21
21
  # .gsub(/(\n\s*\n)+/, "\n")
22
22
  attr_reader :uikit
23
+ attr_reader :root_raw_component_path
23
24
  attr_reader :root_target_path
24
25
  attr_reader :reset_root_path
25
26
 
26
- def initialize(uikit, root_target_path, reset_root_path: false)
27
+ def initialize(uikit, root_raw_component_path, root_target_path, reset_root_path: false)
27
28
  @uikit = uikit
29
+ @root_raw_component_path = root_raw_component_path
28
30
  @root_target_path = root_target_path
29
31
  @reset_root_path = reset_root_path
30
32
  end
@@ -59,7 +61,7 @@ module TailwindDsl
59
61
  def process_group(design_system_name, group)
60
62
  group.files.each do |file|
61
63
  # puts "DSN: #{design_system_name}, GRP: #{group.type}, FILE: #{file.file}"
62
- data = Data.new(design_system_name, group, file)
64
+ data = Data.new(design_system_name, group, file, root_raw_component_path)
63
65
 
64
66
  unless data.source.exist?
65
67
  puts "Source file does not exist: #{data.source.file}"
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TailwindDsl
4
+ module Etl
5
+ # Base class for all ETL data objects that load/persist JSON data
6
+ class Element
7
+ # Get the value of an argument from a hash
8
+ #
9
+ # @param args [Hash] The hash of arguments
10
+ # @param key [String, Symbol] The key to look up
11
+ # @param guard [String] The error message to raise if the key is not found. Guards are optional.
12
+ # @param default [Object] The default value to return if the key is not found. Also optional, defaults to nil.
13
+ def grab_arg(args, key, guard: nil, default: nil)
14
+ value = args[key.to_sym] || args[key.to_s]
15
+
16
+ raise guard if value.nil? && guard
17
+
18
+ value || default
19
+ end
20
+ end
21
+ end
22
+ end
@@ -6,19 +6,15 @@ module TailwindDsl
6
6
  # Design System
7
7
  #
8
8
  # DesignSystem represents a collection of Tailwind CSS components that follow a specific design system
9
- class DesignSystem
9
+ class DesignSystem < TailwindDsl::Etl::Element
10
10
  attr_accessor :name
11
- attr_accessor :path
12
11
  attr_accessor :stats
13
12
  attr_accessor :groups
14
13
 
15
- def initialize(name:, path:, stats: {}, groups: [])
16
- @name = name
17
- @path = path
18
- @stats = stats
19
-
20
- @groups = []
21
- groups.each { |group| add_group(group) }
14
+ def initialize(**args)
15
+ @name = grab_arg(args, :name, guard: 'Missing name')
16
+ @stats = grab_arg(args, :stats, default: {})
17
+ @groups = grab_arg(args, :groups, default: []).map { |group| convert_group(group) }.compact
22
18
  end
23
19
 
24
20
  def add_group(group)
@@ -34,7 +30,6 @@ module TailwindDsl
34
30
  def to_h
35
31
  {
36
32
  name: name,
37
- path: path,
38
33
  stats: stats,
39
34
  groups: groups.map(&:to_h)
40
35
  }
@@ -46,7 +41,7 @@ module TailwindDsl
46
41
  return nil if group.nil?
47
42
 
48
43
  return group if group.is_a?(Group)
49
- return Group.new(group) if group.is_a?(Hash)
44
+ return Group.new(**group) if group.is_a?(Hash)
50
45
 
51
46
  puts "Unknown group type: #{group.class}"
52
47
  nil
@@ -6,21 +6,20 @@ module TailwindDsl
6
6
  # Group
7
7
  #
8
8
  # Group represents a collection of Tailwind CSS components withing a named group or category
9
- class Group
9
+ class Group < TailwindDsl::Etl::Element
10
10
  attr_accessor :key
11
11
  attr_accessor :type
12
12
  attr_accessor :folder
13
13
  attr_accessor :sub_keys
14
14
  attr_accessor :files
15
15
 
16
- def initialize(key:, type:, folder:, sub_keys:, files: [])
17
- @key = key
18
- @type = type
19
- @folder = folder
20
- @sub_keys = sub_keys
16
+ def initialize(**args)
17
+ @key = grab_arg(args, :key, guard: 'Missing key')
18
+ @type = grab_arg(args, :type, guard: 'Missing type')
19
+ @folder = grab_arg(args, :folder, guard: 'Missing folder')
20
+ @sub_keys = grab_arg(args, :sub_keys, guard: 'Missing sub_keys')
21
21
 
22
- @files = []
23
- files.each { |file| add_file(file) }
22
+ @files = grab_arg(args, :files, default: []).map { |file| convert_file(file) }.compact
24
23
  end
25
24
 
26
25
  def add_file(file)
@@ -49,7 +48,7 @@ module TailwindDsl
49
48
  return nil if file.nil?
50
49
 
51
50
  return file if file.is_a?(SourceFile)
52
- return SourceFile.new(file) if file.is_a?(Hash)
51
+ return SourceFile.new(**file) if file.is_a?(Hash)
53
52
 
54
53
  puts "Unknown file type: #{file.class}"
55
54
  nil
@@ -6,31 +6,26 @@ module TailwindDsl
6
6
  # Source File
7
7
  #
8
8
  # SourceFile represents a list of source files that contain raw Tailwind CSS components
9
- class SourceFile
9
+ class SourceFile < TailwindDsl::Etl::Element
10
10
  attr_accessor :name
11
11
  attr_accessor :file_name
12
12
  attr_accessor :file_name_only
13
- attr_accessor :absolute_file
14
13
  attr_accessor :file
15
14
  attr_accessor :target
16
15
 
17
- # rubocop:disable Metrics/ParameterLists
18
- def initialize(name:, file_name:, file_name_only:, absolute_file:, file:, target: nil)
19
- @name = name
20
- @file_name = file_name
21
- @file_name_only = file_name_only
22
- @absolute_file = absolute_file
23
- @file = file
24
- @target = convert_target(target)
16
+ def initialize(**args)
17
+ @name = grab_arg(args, :name, guard: 'Missing name')
18
+ @file_name = grab_arg(args, :file_name, guard: 'Missing file_name')
19
+ @file_name_only = grab_arg(args, :file_name_only, guard: 'Missing file_name_only')
20
+ @file = grab_arg(args, :file, guard: 'Missing file')
21
+ @target = convert_target(grab_arg(args, :target))
25
22
  end
26
- # rubocop:enable Metrics/ParameterLists
27
23
 
28
24
  def to_h
29
25
  result = {
30
26
  name: name,
31
27
  file_name: file_name,
32
28
  file_name_only: file_name_only,
33
- absolute_file: absolute_file,
34
29
  file: file
35
30
  }
36
31
  result[:target] = target.to_h if target
@@ -46,7 +41,7 @@ module TailwindDsl
46
41
  when TargetFile
47
42
  target
48
43
  when Hash
49
- TargetFile.new(target)
44
+ TargetFile.new(**target)
50
45
  else
51
46
  raise "Unknown target type: #{target.class}"
52
47
  end
@@ -6,7 +6,7 @@ module TailwindDsl
6
6
  # Target File
7
7
  #
8
8
  # TargetFile represents each sub_file that can be built from a source file, such as HTML Component, Tailwind Config, Settings and Data Structure
9
- class TargetFile
9
+ class TargetFile < TailwindDsl::Etl::Element
10
10
  attr_accessor :html_file
11
11
  attr_accessor :clean_html_file
12
12
  attr_accessor :tailwind_config_file
@@ -14,16 +14,14 @@ module TailwindDsl
14
14
  attr_accessor :data_file
15
15
  attr_accessor :astro_file
16
16
 
17
- # rubocop:disable Metrics/ParameterLists
18
- def initialize(html_file:, clean_html_file:, tailwind_config_file:, settings_file:, data_file:, astro_file:)
19
- @html_file = html_file
20
- @clean_html_file = clean_html_file
21
- @tailwind_config_file = tailwind_config_file
22
- @settings_file = settings_file
23
- @data_file = data_file
24
- @astro_file = astro_file
17
+ def initialize(**args)
18
+ @html_file = grab_arg(args, :html_file, guard: 'Missing html_file')
19
+ @clean_html_file = grab_arg(args, :clean_html_file, guard: 'Missing clean_html_file')
20
+ @tailwind_config_file = grab_arg(args, :tailwind_config_file, guard: 'Missing tailwind_config_file')
21
+ @settings_file = grab_arg(args, :settings_file, guard: 'Missing settings_file')
22
+ @data_file = grab_arg(args, :data_file, guard: 'Missing data_file')
23
+ @astro_file = grab_arg(args, :astro_file, guard: 'Missing astro_file')
25
24
  end
26
- # rubocop:enable Metrics/ParameterLists
27
25
 
28
26
  def to_h
29
27
  {
@@ -54,7 +54,7 @@ module TailwindDsl
54
54
  return nil if design_system.nil?
55
55
 
56
56
  return design_system if design_system.is_a?(DesignSystem)
57
- return DesignSystem.new(design_system) if design_system.is_a?(Hash)
57
+ return DesignSystem.new(**design_system) if design_system.is_a?(Hash)
58
58
 
59
59
  puts "Unknown design_system type: #{design_system.class}"
60
60
  nil
@@ -5,6 +5,7 @@ module TailwindDsl
5
5
  module RawComponents
6
6
  # The component reader will read the raw component files for each UI Kit.
7
7
  class Transformer
8
+ attr_reader :path
8
9
  attr_reader :design_system
9
10
 
10
11
  attr_reader :group_lookup
@@ -12,10 +13,10 @@ module TailwindDsl
12
13
 
13
14
  def call(name, path)
14
15
  @design_system = ::TailwindDsl::Etl::RawComponents::DesignSystem.new(
15
- name: name,
16
- path: path
16
+ name: name
17
17
  )
18
18
 
19
+ @path = path
19
20
  @group_lookup = {}
20
21
 
21
22
  process_files
@@ -30,7 +31,7 @@ module TailwindDsl
30
31
  private
31
32
 
32
33
  def process_files
33
- glob = File.join(design_system.path, '**', '*')
34
+ glob = File.join(path, '**', '*')
34
35
 
35
36
  Dir.glob(glob) do |entry|
36
37
  next if reject?(entry)
@@ -44,7 +45,7 @@ module TailwindDsl
44
45
  # rubocop:disable Metrics/AbcSize
45
46
  def assign_group(entry)
46
47
  target_path = File.directory?(entry) ? entry : File.dirname(entry)
47
- relative_folder = Pathname.new(target_path).relative_path_from(Pathname.new(design_system.path)).to_s
48
+ relative_folder = Pathname.new(target_path).relative_path_from(Pathname.new(path)).to_s
48
49
 
49
50
  group_key = relative_folder == '.' ? '@' : relative_folder.split('/').map { |part| snake.call(part) }.join('.')
50
51
 
@@ -90,11 +91,11 @@ module TailwindDsl
90
91
  end
91
92
 
92
93
  def source_file(entry, folder, target)
94
+ # absolute_file: entry,
93
95
  ::TailwindDsl::Etl::RawComponents::SourceFile.new(
94
96
  name: File.basename(entry),
95
97
  file_name: File.basename(entry),
96
98
  file_name_only: File.basename(entry, File.extname(entry)),
97
- absolute_file: entry,
98
99
  file: File.join(folder, File.basename(entry)),
99
100
  target: target
100
101
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindDsl
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
data/lib/tailwind_dsl.rb CHANGED
@@ -7,6 +7,8 @@ require_relative 'tailwind_dsl/version'
7
7
 
8
8
  require_relative 'tailwind_dsl/etl/raw_components/director'
9
9
  require_relative 'tailwind_dsl/etl/raw_components/transformer'
10
+
11
+ require_relative 'tailwind_dsl/etl/element'
10
12
  require_relative 'tailwind_dsl/etl/raw_components/schema/target_file'
11
13
  require_relative 'tailwind_dsl/etl/raw_components/schema/source_file'
12
14
  require_relative 'tailwind_dsl/etl/raw_components/schema/group'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tailwind_dsl",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "tailwind_dsl",
9
- "version": "0.0.6",
9
+ "version": "0.0.7",
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.6",
3
+ "version": "0.0.7",
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.6
4
+ version: 0.0.7
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-12 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdlet
@@ -2201,6 +2201,7 @@ files:
2201
2201
  - lib/tailwind_dsl/astro_demo/generate_astro_page_data.rb
2202
2202
  - lib/tailwind_dsl/etl/component_structures/data.rb
2203
2203
  - lib/tailwind_dsl/etl/component_structures/generator.rb
2204
+ - lib/tailwind_dsl/etl/element.rb
2204
2205
  - lib/tailwind_dsl/etl/raw_components/director.rb
2205
2206
  - lib/tailwind_dsl/etl/raw_components/schema/design_system.rb
2206
2207
  - lib/tailwind_dsl/etl/raw_components/schema/group.rb