klenod-build 0.0.17 → 0.0.19

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: bb4a8187db76f9671235b269a3f9f40649ac30a7b53b57e95795a7d1e319094c
4
+ data.tar.gz: 78343ed3c333874c7d182f345defc10809fdbeb24be7d527b53be4ae541e108f
5
5
  SHA512:
6
- metadata.gz: cb64e39cf3daedff82d30572bb92c136a3091118a843aa7e9180c40dd83e5e074be8a017867744fb4921a6a092eab366095a510639bacf8aba37a2859c013dd3
7
- data.tar.gz: 9d9ad93cbfc302d0db9e4bddca0cb333929fe62480791bfadef0848bc09c4459fd6ed5145fa93f444ed077f1f7e63d172900a7065f81a6e0e24d7f0cf71c9eed
6
+ metadata.gz: 7c074cba0f0b87478c46e80f90fdfc4b6913d93f8b85fb5b6800083bad3bfe9ac2df2f3a3e21a9e32f351581f719eec88b496e0de65c1b7c237ce6d2822f03f4
7
+ data.tar.gz: 7b68a319b15f6f3d1039f689b4f862a25a2c49a2d7f59a95c7d6a64944b3a5b559e065d704057dc22c6ac514cbc85b4349ac75de405f9353977182dd103a68ea
@@ -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,79 @@ 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
+ unless source[index] == "="
93
+ pairs << [name, "true"]
94
+ next
95
+ end
96
+
97
+ index += 1
98
+ index += 1 while source[index]&.match?(/\s/)
99
+ value_start = index
100
+ depth = 0
101
+ quote = nil
102
+ escaped = false
103
+
104
+ while index < source.length
105
+ character = source[index]
106
+ if quote
107
+ if escaped
108
+ escaped = false
109
+ elsif character == "\\"
110
+ escaped = true
111
+ elsif character == quote
112
+ quote = nil
113
+ end
114
+ else
115
+ case character
116
+ when "'", '"' then quote = character
117
+ when "(", "[", "{" then depth += 1
118
+ when ")", "]", "}" then depth -= 1
119
+ when " ", "\t"
120
+ break if depth.zero? && attribute_boundary?(source[index..])
121
+ end
122
+ end
123
+ index += 1
124
+ end
125
+
126
+ value = source[value_start...index].strip
127
+ return nil if value.empty? || depth.negative? || quote || !Ripper.sexp(value)
128
+
129
+ pairs << [name, value]
130
+ end
131
+
132
+ pairs
133
+ end
134
+
135
+ def attribute_boundary?(remaining_source)
136
+ attribute_sequence?(remaining_source)
137
+ end
138
+
139
+ def attribute_sequence?(source)
140
+ source = source.lstrip
141
+ name = source.match(/\A[-:@#\w.]*\w[-:@#\w.]*/)&.to_s
142
+ return false unless name
143
+ return false if %w[true false nil].include?(name)
144
+
145
+ rest = source[name.length..]
146
+ return true if rest.empty? || rest.lstrip.start_with?("=")
147
+ return false unless rest.start_with?(" ", "\t")
148
+
149
+ attribute_sequence?(rest)
150
+ end
151
+
65
152
  def literal_class_names_from_old_attributes(source)
66
153
  parsed = ::Haml::AttributeParser.parse(source)
67
154
  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.19"
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.19
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.19
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.19
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: async
28
28
  requirement: !ruby/object:Gem::Requirement