klenod-build 0.0.17 → 0.0.18

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: d24b06569546f0b32ba9aebee8e17b989b9cd67198714952404b818dbae7d425
4
- data.tar.gz: c61a9de1db41a5258cf2f9ae742ab9256c69fa06df0ef799035db39df89630f2
3
+ metadata.gz: b36ee8205987d239a6301d55da7f4ef92548303139d04b5bbc2246ba6e94e8e3
4
+ data.tar.gz: 8f6db6e13f72e4b290b91d115df9e38e8e907100db677baea5a5fec047bc6ae0
5
5
  SHA512:
6
- metadata.gz: cb64e39cf3daedff82d30572bb92c136a3091118a843aa7e9180c40dd83e5e074be8a017867744fb4921a6a092eab366095a510639bacf8aba37a2859c013dd3
7
- data.tar.gz: 9d9ad93cbfc302d0db9e4bddca0cb333929fe62480791bfadef0848bc09c4459fd6ed5145fa93f444ed077f1f7e63d172900a7065f81a6e0e24d7f0cf71c9eed
6
+ metadata.gz: d9572bdc8295bfa42c28a88057e6625d1b105cfb8b7c9f51bc7d426ffb0e090c472237f86f549258da64b1095931921e5259a78a41050590b4d67254c92590c5
7
+ data.tar.gz: e4b49528fe297b00c61d9f45bd8b780e88d485c9c3c4e1f37c1a28ce63ee128af0c64bccdaa68567197f0aa5beae51f568fd4371cb4d4a273c82ca7204a73b19
@@ -556,7 +556,11 @@ module Klenod
556
556
  record
557
557
  .resolved_dependencies
558
558
  .reject { skip_asset_dependency?(it, type:) }
559
- .map(&:module_id)
559
+ if type == :css
560
+ regular_dependencies, companion_styles = dependency_ids.partition { |dependency| dependency.dependency.kind != :companion_style }
561
+ dependency_ids = [*regular_dependencies, *companion_styles]
562
+ end
563
+ dependency_ids = dependency_ids.map(&:module_id)
560
564
 
561
565
  if module_id.extname == ".css"
562
566
  dependency_ids.flat_map { |dependency_id| ordered_module_ids_for_assets(dependency_id, seen, type: type) } + [module_id]
@@ -35,6 +35,20 @@ module Klenod
35
35
  result
36
36
  end
37
37
 
38
+ # Haml's parenthesized-attribute parser accepts only a bare variable
39
+ # after `=`. For example, it reads `video_id=video.id` as the value
40
+ # `video` plus a `.id` class. Extend that form to ordinary Ruby
41
+ # member and index expressions while leaving all other attributes on
42
+ # Haml's native parsing path.
43
+ def parse_new_attributes(text)
44
+ balanced, rest = ::Haml::Util.balance(text, "(", ")")
45
+ pairs = balanced && extended_attribute_pairs(balanced[1...-1])
46
+ return super unless pairs&.any? { |_name, value| value.match?(/[.\[]/) }
47
+
48
+ dynamic = pairs.reduce("{") { |source, (name, value)| "#{source}#{::Haml::Util.inspect_obj(name)} => #{value}," } << "}"
49
+ [[{}, dynamic], rest, @line.index + 1]
50
+ end
51
+
38
52
  def annotate_tag_nodes(root)
39
53
  queue = root.children.dup
40
54
  until queue.empty?
@@ -62,6 +76,59 @@ module Klenod
62
76
  {shorthand: shorthand, literal: literal}
63
77
  end
64
78
 
79
+ def extended_attribute_pairs(source)
80
+ pairs = []
81
+ index = 0
82
+
83
+ loop do
84
+ index += 1 while source[index]&.match?(/\s/)
85
+ break if index >= source.length
86
+
87
+ name = source[index..].match(/\A[-:@#\w.]+/)&.to_s
88
+ return nil unless name
89
+
90
+ index += name.length
91
+ index += 1 while source[index]&.match?(/\s/)
92
+ return nil unless source[index] == "="
93
+
94
+ index += 1
95
+ index += 1 while source[index]&.match?(/\s/)
96
+ value_start = index
97
+ depth = 0
98
+ quote = nil
99
+ escaped = false
100
+
101
+ while index < source.length
102
+ character = source[index]
103
+ if quote
104
+ if escaped
105
+ escaped = false
106
+ elsif character == "\\"
107
+ escaped = true
108
+ elsif character == quote
109
+ quote = nil
110
+ end
111
+ else
112
+ case character
113
+ when "'", '"' then quote = character
114
+ when "(", "[", "{" then depth += 1
115
+ when ")", "]", "}" then depth -= 1
116
+ when " ", "\t"
117
+ break if depth.zero? && source[index..].match?(/\A\s+[-:@#\w.]+\s*=/)
118
+ end
119
+ end
120
+ index += 1
121
+ end
122
+
123
+ value = source[value_start...index].strip
124
+ return nil if value.empty? || depth.negative? || quote
125
+
126
+ pairs << [name, value]
127
+ end
128
+
129
+ pairs
130
+ end
131
+
65
132
  def literal_class_names_from_old_attributes(source)
66
133
  parsed = ::Haml::AttributeParser.parse(source)
67
134
  return [] unless parsed&.key?("class")
@@ -489,7 +489,9 @@ module Klenod
489
489
  def render_ruby_filter(node)
490
490
  source = to_source(node)
491
491
  parsed = (node if node.is_a?(Fragment) && node.node?) || statements(source)
492
- return statements("begin\n#{indent(source, 2)}\n nil\nend") unless parsed
492
+ unless parsed&.node?
493
+ raise_ruby_parse_error(source, line_no: nil, context: "Could not parse Ruby filter")
494
+ end
493
495
 
494
496
  fragment(
495
497
  ast_begin([
@@ -497,8 +499,6 @@ module Klenod
497
499
  nil_node
498
500
  ])
499
501
  )
500
- rescue SyntaxTree::Parser::ParseError
501
- statements("begin\n#{indent(source, 2)}\n nil\nend")
502
502
  end
503
503
 
504
504
  def format_node(node)
@@ -575,16 +575,20 @@ module Klenod
575
575
  line_offsets = [0]
576
576
  source.each_line(chomp: false) { |line| line_offsets << line_offsets.last + line.length }
577
577
 
578
- Ripper
579
- .lex(source)
580
- .filter_map do |(line, column), type, token, _state|
578
+ tokens = Ripper.lex(source)
579
+
580
+ tokens
581
+ .each_with_index
582
+ .filter_map do |((line, column), type, token, _state), index|
581
583
  kind, prefix, pattern = VARIABLE_TOKEN_KINDS[type]
582
584
  receiver = @variables[kind]
583
585
  if type == :on_gvar && token == "$*" && receiver
584
586
  [offset_for(line_offsets, line, column), token.length, receiver]
585
587
  elsif receiver && token.match?(pattern)
586
588
  name = token.delete_prefix(prefix)
587
- [offset_for(line_offsets, line, column), token.length, "(#{receiver})[#{symbol_source(name)}]"]
589
+ replacement = "(#{receiver})[#{symbol_source(name)}]"
590
+ replacement = "{#{replacement}}" if tokens[index - 1]&.fetch(1) == :on_embvar
591
+ [offset_for(line_offsets, line, column), token.length, replacement]
588
592
  end
589
593
  end
590
594
  .reverse_each
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Klenod
4
4
  module Build
5
- VERSION = "0.0.17"
5
+ VERSION = "0.0.18"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klenod-build
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrés Alin
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.17
18
+ version: 0.0.18
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.17
25
+ version: 0.0.18
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: async
28
28
  requirement: !ruby/object:Gem::Requirement