asciisourcerer 0.3.0 → 0.3.1

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: 758bb9f8f554228a7d67b894471d79d966b0e6495b7b2da2854dcdfb18544e40
4
- data.tar.gz: c82bb9ba5cf1391d78feb56682c470c6ded9d49f0d469678eb27801e1e30e9af
3
+ metadata.gz: 3c7773a8343dbad45adce3b1c32d959ed8e8da23afb1779e308999801eb32404
4
+ data.tar.gz: a9ff1c4838338f0302e9dbb202092309254be9c73dfe245f6ea61594a38e966e
5
5
  SHA512:
6
- metadata.gz: d64e160a0e2ddc95e8114781c88e8f1a25cfaad689c43fd121e4bcae2c68b3e6bd8d5bc332464e496938b5d1e8cd769ce90ea74943c3d29edea593c560793d9b
7
- data.tar.gz: 3a3a656576871fe4fdb3b4927d8cd3ed5b094f8f959ecbd2ccaf2ab4db16551ec6a136948526d137ff43b66ca043b808d935c8a22babd4bbd39db38811c2565e
6
+ metadata.gz: e49749d692bd70ce7196fb54312e016b0daf5074d3949c49a4586e3c7f3da7e85d9e3c9b0d50013c3d8c8e8a14a9353323cd0f195cda0255956657aee42bf441
7
+ data.tar.gz: 9d10b6d87d315d5d5d254103cc82a3491b43f11fb784da16dc0516ee4697373e5b45d75a2aec29b4bab90d70e74d32f48ee5194108d576b5e7f4cd4f206506f9
data/README.adoc CHANGED
@@ -39,7 +39,7 @@ endif::[]
39
39
  :this_prod_vrsn_major: 0
40
40
  :this_prod_vrsn_minor: 3
41
41
  :this_prod_vrsn_majmin: {this_prod_vrsn_major}.{this_prod_vrsn_minor}
42
- :this_prod_vrsn_patch: 0
42
+ :this_prod_vrsn_patch: 1
43
43
  :this_prod_vrsn: {this_prod_vrsn_majmin}.{this_prod_vrsn_patch}
44
44
  :next_prod_vrsn: 0.4.0
45
45
  // end::global-settings[]
@@ -71,9 +71,29 @@ module Sourcerer
71
71
  # but do not write.
72
72
  # @return [CastResult]
73
73
  def self.init prime_path, target_path, data: {}, dry_run: false
74
- prime_text = File.read(prime_path)
75
- clean_text = strip_meta_blocks(prime_text)
76
- rendered = data.empty? ? clean_text : render_liquid_string(clean_text, data)
74
+ segments = parse_prime_segments(File.read(prime_path))
75
+
76
+ liquid_preamble = segments
77
+ .find { |s| s.is_a?(BlockParser::Block) && s.tag == '_liquid' }
78
+ &.content.to_s
79
+
80
+ clean_text = segments
81
+ .reject { |s| s.is_a?(BlockParser::Block) && s.tag.start_with?('_') }
82
+ .map { |s| s.is_a?(BlockParser::Block) ? "#{s.open_line}#{s.content}#{s.close_line}" : s.content }
83
+ .join
84
+
85
+ rendered = if data.empty? && liquid_preamble.empty?
86
+ clean_text
87
+ else
88
+ # Wrap the preamble in a silent capture block so the assign statements
89
+ # populate variables without emitting any whitespace into the output.
90
+ full = if liquid_preamble.empty?
91
+ clean_text
92
+ else
93
+ "{%- capture __preamble__ -%}#{liquid_preamble}{%- endcapture -%}#{clean_text}"
94
+ end
95
+ render_liquid_string(full, data)
96
+ end
77
97
 
78
98
  unless dry_run
79
99
  FileUtils.mkdir_p(File.dirname(File.expand_path(target_path)))
@@ -174,15 +194,22 @@ module Sourcerer
174
194
  # meaningful during the prime→target rendering pass, not in the output file.
175
195
  # @api private
176
196
  def self.strip_meta_blocks text
197
+ parse_prime_segments(text)
198
+ .reject { |s| s.is_a?(BlockParser::Block) && s.tag.start_with?('_') }
199
+ .map { |s| s.is_a?(BlockParser::Block) ? "#{s.open_line}#{s.content}#{s.close_line}" : s.content }
200
+ .join
201
+ end
202
+
203
+ # Parse a prime template using the default tag patterns.
204
+ # Shared by {.init} and {.strip_meta_blocks} to avoid repeating
205
+ # the +build_tag_patterns+ / +parse+ boilerplate.
206
+ # @api private
207
+ def self.parse_prime_segments text
177
208
  tag_patterns = BlockParser.build_tag_patterns(
178
209
  BlockParser::DEFAULT_TAG_SYNTAX_START,
179
210
  BlockParser::DEFAULT_TAG_SYNTAX_END,
180
211
  BlockParser::DEFAULT_COMMENT_SYNTAX_PATTERNS)
181
- segments = BlockParser.parse(text, canonical_prefix: '', tag_patterns: tag_patterns)
182
- segments
183
- .reject { |s| s.is_a?(BlockParser::Block) && s.tag.start_with?('_') }
184
- .map { |s| s.is_a?(BlockParser::Block) ? "#{s.open_line}#{s.content}#{s.close_line}" : s.content }
185
- .join
212
+ BlockParser.parse(text, canonical_prefix: '', tag_patterns: tag_patterns)
186
213
  end
187
214
 
188
215
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sourcerer
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciisourcerer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DocOps Lab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-01 00:00:00.000000000 Z
11
+ date: 2026-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor