klenod-build 0.0.9 → 0.0.11
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 +4 -4
- data/lib/klenod/build/plugins/haml_plugin/helper_source.rb +0 -6
- data/lib/klenod/build/plugins/haml_plugin/transformer/ruby_builder.rb +24 -3
- data/lib/klenod/build/plugins/haml_plugin/transformer.rb +53 -27
- data/lib/klenod/build/plugins/haml_plugin.rb +2 -5
- data/lib/klenod/build/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 971caae6ad82448ab179cd8dc98c0920ac4422a2eea50a11d9a67c1097ecda7c
|
|
4
|
+
data.tar.gz: 8b1e33ab86a8c09a8a659d3caf68cf093b5adb7f33b3c6d988a85913ca865bbd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a664ddf7e161448788a7c5b3c8680acb07b12a16edeaccf9640cd260d8613457e096621ec2649ad3c7c6196364d353436bad856de1e390cb61a45142d6f7423e
|
|
7
|
+
data.tar.gz: eedab53d4360f66b32ff8397f280ce57b9d620d5a54fed5379a7aece96444cea1ef6a98219f5964fa2b7c931b5fce55f252ca62207f3a038bce9d314791e166f
|
|
@@ -427,6 +427,10 @@ module Klenod
|
|
|
427
427
|
expression("HamlHelper.freeze_static(#{argument_source(value)})")
|
|
428
428
|
end
|
|
429
429
|
|
|
430
|
+
def class_values(values)
|
|
431
|
+
source_expressions(values)
|
|
432
|
+
end
|
|
433
|
+
|
|
430
434
|
def script_block(source, body, line_no: nil)
|
|
431
435
|
source = rewrite_ruby_source(source, nil)
|
|
432
436
|
ast_script_block(source, body) || raise_ruby_parse_error(source, line_no: line_no, context: "Could not build Ruby block from Haml script")
|
|
@@ -444,9 +448,26 @@ module Klenod
|
|
|
444
448
|
|
|
445
449
|
def silent_script_with_children(source, body)
|
|
446
450
|
source = rewrite_ruby_source(source, nil)
|
|
451
|
+
return_with_children = false
|
|
452
|
+
|
|
453
|
+
# A modifier return with an indented Haml block returns that block
|
|
454
|
+
# when the condition matches. Keeping the return and its children
|
|
455
|
+
# as sequential statements would instead evaluate the children
|
|
456
|
+
# after the modifier has fallen through.
|
|
457
|
+
if source == "return"
|
|
458
|
+
source = "return #{argument_source(body)}"
|
|
459
|
+
return_with_children = true
|
|
460
|
+
elsif (match = source.match(/\Areturn\s+(if|unless)\s+(.+)\z/))
|
|
461
|
+
branch, condition = match.captures
|
|
462
|
+
source = "#{branch} #{condition}\n#{indent("return #{argument_source(body)}", 2)}\nend"
|
|
463
|
+
return_with_children = true
|
|
464
|
+
end
|
|
465
|
+
|
|
447
466
|
statements = parse_statements(source)
|
|
448
467
|
return raise(ArgumentError, "Could not parse Haml silent script: #{source.inspect}") unless statements
|
|
449
468
|
|
|
469
|
+
return Fragment.new(source, statements) if return_with_children
|
|
470
|
+
|
|
450
471
|
node = ast_begin([*statement_body_for(statements), *statement_body_for(body)])
|
|
451
472
|
Fragment.new(["begin", indent(source, 2), indent(to_source(body), 2), "end"].join("\n"), node)
|
|
452
473
|
end
|
|
@@ -595,12 +616,12 @@ module Klenod
|
|
|
595
616
|
children = children.map { |child| expression_fragment(child) }
|
|
596
617
|
props = props.dup
|
|
597
618
|
attribute_splats = props.delete(:__klenod_attribute_splats__) || []
|
|
619
|
+
prop_sources = ["{#{keyword_props_source(props, mark: mark).join(", ")}}", *attribute_splats.map { |value| argument_source(value) }]
|
|
598
620
|
|
|
599
621
|
source_parts = [
|
|
600
622
|
to_source(tag),
|
|
601
623
|
*children.map { |child| argument_source(child) },
|
|
602
|
-
|
|
603
|
-
*attribute_splats.map { |value| "**#{argument_source(value)}" }
|
|
624
|
+
"**HamlHelper.merge_props(self.class, #{prop_sources.join(", ")})"
|
|
604
625
|
].compact
|
|
605
626
|
Fragment.new("#{to_source(factory)}[#{source_parts.join(", ")}]", nil)
|
|
606
627
|
end
|
|
@@ -680,7 +701,7 @@ module Klenod
|
|
|
680
701
|
def block_source(source, body)
|
|
681
702
|
body_source = to_source(body)
|
|
682
703
|
|
|
683
|
-
if source.include?("{")
|
|
704
|
+
if source.include?("{") && !source.end_with?(" do")
|
|
684
705
|
"#{source} #{body_source} }"
|
|
685
706
|
else
|
|
686
707
|
[source, indent(body_source, 2), "end"].join("\n")
|
|
@@ -216,7 +216,7 @@ module Klenod
|
|
|
216
216
|
measure_compile(:haml_build_expression_list) { builder.expressions(expressions) }
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
-
def compile_node_expressions(nodes, factory:, builder:, markdown_compiler:, styleable: false)
|
|
219
|
+
def compile_node_expressions(nodes, factory:, builder:, markdown_compiler:, styleable: false, join_adjacent_plain_text: false)
|
|
220
220
|
expressions = []
|
|
221
221
|
previous_node = nil
|
|
222
222
|
index = 0
|
|
@@ -224,7 +224,21 @@ module Klenod
|
|
|
224
224
|
while index < nodes.length
|
|
225
225
|
node = nodes[index]
|
|
226
226
|
|
|
227
|
-
if
|
|
227
|
+
if join_adjacent_plain_text && node.type == :plain
|
|
228
|
+
plain_nodes = [node]
|
|
229
|
+
index += 1
|
|
230
|
+
|
|
231
|
+
while index < nodes.length && nodes[index].type == :plain
|
|
232
|
+
plain_nodes << nodes[index]
|
|
233
|
+
index += 1
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
text = plain_nodes.map { it.value.fetch(:text).strip }.reject(&:empty?).join(" ")
|
|
237
|
+
next if text.empty?
|
|
238
|
+
|
|
239
|
+
expression = builder.marked_expression(source_mark(plain_nodes.first, builder: builder), builder.literal(text))
|
|
240
|
+
node = plain_nodes.last
|
|
241
|
+
elsif script_node?(node) && !continuation?(node)
|
|
228
242
|
group = [node]
|
|
229
243
|
index += 1
|
|
230
244
|
|
|
@@ -453,7 +467,14 @@ module Klenod
|
|
|
453
467
|
unless node.children.empty?
|
|
454
468
|
children.concat(
|
|
455
469
|
measure_compile_detail(:haml_compile_tag_children) do
|
|
456
|
-
compile_node_expressions(
|
|
470
|
+
compile_node_expressions(
|
|
471
|
+
node.children,
|
|
472
|
+
factory: factory,
|
|
473
|
+
styleable: styleable,
|
|
474
|
+
builder: builder,
|
|
475
|
+
markdown_compiler: markdown_compiler,
|
|
476
|
+
join_adjacent_plain_text: true
|
|
477
|
+
)
|
|
457
478
|
end
|
|
458
479
|
)
|
|
459
480
|
end
|
|
@@ -602,35 +623,40 @@ module Klenod
|
|
|
602
623
|
|
|
603
624
|
def dynamic_attributes(node, builder:, props:)
|
|
604
625
|
dynamic_attributes = node.value.fetch(:dynamic_attributes)
|
|
605
|
-
|
|
606
|
-
return {}
|
|
626
|
+
sources = [dynamic_attributes.new, dynamic_attributes.old].compact
|
|
627
|
+
return {} if sources.empty?
|
|
607
628
|
|
|
608
629
|
measure_compile(:haml_compile_dynamic_attributes) do
|
|
609
|
-
source = builder.line_rewritten_source(source, node.line)
|
|
610
|
-
simple = simple_dynamic_attributes(source, builder: builder) unless @event_handler
|
|
611
|
-
if simple
|
|
612
|
-
simple.each { |key, value| props[key] = value }
|
|
613
|
-
return simple
|
|
614
|
-
end
|
|
615
|
-
|
|
616
|
-
hash = builder.hash_expression(source, line_no: node.line)
|
|
617
|
-
unless hash
|
|
618
|
-
builder.ruby_parse_error(source, line_no: node.line, context: "Could not parse Haml dynamic attributes")
|
|
619
|
-
end
|
|
620
|
-
|
|
621
630
|
dynamic = {}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
631
|
+
sources.each do |source|
|
|
632
|
+
source = builder.line_rewritten_source(source, node.line)
|
|
633
|
+
simple = simple_dynamic_attributes(source, builder: builder) unless @event_handler
|
|
634
|
+
if simple
|
|
635
|
+
simple.each do |key, value|
|
|
636
|
+
dynamic[key] = value
|
|
637
|
+
props[key] = value
|
|
638
|
+
end
|
|
627
639
|
next
|
|
628
640
|
end
|
|
629
641
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
642
|
+
hash = builder.hash_expression(source, line_no: node.line)
|
|
643
|
+
unless hash
|
|
644
|
+
builder.ruby_parse_error(source, line_no: node.line, context: "Could not parse Haml dynamic attributes")
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
hash.node.assocs.each do |assoc|
|
|
648
|
+
if assoc.is_a?(SyntaxTree::AssocSplat)
|
|
649
|
+
splat_source = hash.source[assoc.value.location.start_char...assoc.value.location.end_char]
|
|
650
|
+
props[ATTRIBUTE_SPLATS_KEY] ||= []
|
|
651
|
+
props[ATTRIBUTE_SPLATS_KEY] << builder.expression(splat_source)
|
|
652
|
+
next
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
key = attribute_key(assoc.key, builder: builder)
|
|
656
|
+
value = event_handler_value(key, assoc.value, builder: builder) || attribute_value(assoc, builder: builder)
|
|
657
|
+
dynamic[key] = value
|
|
658
|
+
props[key] = value
|
|
659
|
+
end
|
|
634
660
|
end
|
|
635
661
|
dynamic
|
|
636
662
|
end
|
|
@@ -715,7 +741,7 @@ module Klenod
|
|
|
715
741
|
return
|
|
716
742
|
end
|
|
717
743
|
|
|
718
|
-
props[:class] = builder.
|
|
744
|
+
props[:class] = builder.class_values(class_values)
|
|
719
745
|
end
|
|
720
746
|
end
|
|
721
747
|
|
|
@@ -33,7 +33,6 @@ module Klenod
|
|
|
33
33
|
I18N_OPTIONS = %i[class constant].freeze
|
|
34
34
|
HAML_HELPER_SPECIFIER = "virtual:klenod/haml_helper"
|
|
35
35
|
HAML_HELPER_MODULE_ID = ModuleId.new("#{HAML_HELPER_SPECIFIER}.rb", nil)
|
|
36
|
-
STATIC_CLASS_SOURCE_PATTERN = /^[ \t]*(?:%[-:\w]+)?(?:#[\w-]+)?\.[\w-]|[({][^)}\n]*\bclass\s*=/m
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
module HamlPlugin
|
|
@@ -51,7 +50,6 @@ module Klenod
|
|
|
51
50
|
I18N_OPTIONS = HamlPlugin::I18N_OPTIONS
|
|
52
51
|
HAML_HELPER_SPECIFIER = HamlPlugin::HAML_HELPER_SPECIFIER
|
|
53
52
|
HAML_HELPER_MODULE_ID = HamlPlugin::HAML_HELPER_MODULE_ID
|
|
54
|
-
STATIC_CLASS_SOURCE_PATTERN = HamlPlugin::STATIC_CLASS_SOURCE_PATTERN
|
|
55
53
|
|
|
56
54
|
def self.parse_haml(...)
|
|
57
55
|
HamlPlugin.parse_haml(...)
|
|
@@ -170,9 +168,8 @@ module Klenod
|
|
|
170
168
|
class_names_runtime_dependency = class_names_runtime_dependency(module_id)
|
|
171
169
|
dependencies << class_names_runtime_dependency
|
|
172
170
|
styles_source = styles_source_for(builder, style_dependencies, class_names_runtime_dependency: class_names_runtime_dependency)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
dependencies << haml_helper_dependency if haml_helper_dependency
|
|
171
|
+
haml_helper_dependency = haml_helper_dependency(module_id)
|
|
172
|
+
dependencies << haml_helper_dependency
|
|
176
173
|
translations_source = builder.frozen_literal(translations_for(context, module_id)).source
|
|
177
174
|
component_class_name = component_class_name(module_id)
|
|
178
175
|
import_rewriter =
|
data/lib/klenod/build/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.0.11
|
|
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.
|
|
18
|
+
version: 0.0.11
|
|
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.
|
|
25
|
+
version: 0.0.11
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: async
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|