poml 0.0.2 → 0.0.3
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/poml/components/data.rb +51 -12
- data/lib/poml/components/utilities.rb +75 -3
- data/lib/poml/components.rb +2 -0
- data/lib/poml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57f8a3904a43267d79cbc6fb76465dd51c05da5923e58635304242eb90b04b96
|
4
|
+
data.tar.gz: 591512861013d2ae3d302b342b4678696a4d3691c98a26a2d9cdcd042ec70422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba9aeb9b1e06de010b5daa9489d847dc41f5f5d73a9a02e70d81432e997b1c3a3a32116cf9d85ee2f4c70755024201272e62951381cf6363be59dc807c6c55b0
|
7
|
+
data.tar.gz: 2f763c41a44b095f64fbe75cc64f58af266b50c8d966e0d44e6c382945a21fdde9abdd83a49b17ab57608c90a8481fb3066eca6dbc3633533e16269af1693f61
|
data/lib/poml/components/data.rb
CHANGED
@@ -12,10 +12,10 @@ module Poml
|
|
12
12
|
columns_attr = get_attribute('columns')
|
13
13
|
parser = get_attribute('parser', 'auto')
|
14
14
|
syntax = get_attribute('syntax')
|
15
|
-
selected_columns =
|
16
|
-
selected_records =
|
17
|
-
max_records =
|
18
|
-
max_columns =
|
15
|
+
selected_columns = parse_array_attribute('selectedColumns')
|
16
|
+
selected_records = parse_array_attribute('selectedRecords')
|
17
|
+
max_records = parse_integer_attribute('maxRecords')
|
18
|
+
max_columns = parse_integer_attribute('maxColumns')
|
19
19
|
|
20
20
|
# Load data from source or use provided records
|
21
21
|
data = if src
|
@@ -136,7 +136,12 @@ module Poml
|
|
136
136
|
def parse_records_attribute(records_attr)
|
137
137
|
# Handle string records (JSON) or already parsed arrays
|
138
138
|
records = if records_attr.is_a?(String)
|
139
|
-
|
139
|
+
begin
|
140
|
+
JSON.parse(records_attr)
|
141
|
+
rescue JSON::ParserError => e
|
142
|
+
# Return empty records on parse error
|
143
|
+
return { records: [], columns: [] }
|
144
|
+
end
|
140
145
|
else
|
141
146
|
records_attr
|
142
147
|
end
|
@@ -150,6 +155,38 @@ module Poml
|
|
150
155
|
{ records: records.is_a?(Array) ? records : [records], columns: columns }
|
151
156
|
end
|
152
157
|
|
158
|
+
def parse_array_attribute(attr_name)
|
159
|
+
attr_value = get_attribute(attr_name)
|
160
|
+
return nil unless attr_value
|
161
|
+
|
162
|
+
if attr_value.is_a?(String)
|
163
|
+
begin
|
164
|
+
parsed = JSON.parse(attr_value)
|
165
|
+
parsed.is_a?(Array) ? parsed : nil
|
166
|
+
rescue JSON::ParserError
|
167
|
+
# Try to handle as slice notation
|
168
|
+
attr_value.include?(':') ? attr_value : nil
|
169
|
+
end
|
170
|
+
elsif attr_value.is_a?(Array)
|
171
|
+
attr_value
|
172
|
+
else
|
173
|
+
nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def parse_integer_attribute(attr_name)
|
178
|
+
attr_value = get_attribute(attr_name)
|
179
|
+
return nil unless attr_value
|
180
|
+
|
181
|
+
if attr_value.is_a?(String)
|
182
|
+
attr_value.to_i
|
183
|
+
elsif attr_value.is_a?(Integer)
|
184
|
+
attr_value
|
185
|
+
else
|
186
|
+
nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
153
190
|
def parse_html_table_children
|
154
191
|
records = []
|
155
192
|
columns = []
|
@@ -219,13 +256,15 @@ module Poml
|
|
219
256
|
end
|
220
257
|
end
|
221
258
|
|
222
|
-
# Apply max records
|
223
|
-
if max_records && records.length > max_records
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
259
|
+
# Apply max records - simple truncation with ellipsis row
|
260
|
+
if max_records && max_records > 0 && records.length > max_records
|
261
|
+
truncated_records = records[0...max_records]
|
262
|
+
# Add ellipsis row if we truncated
|
263
|
+
if records.length > max_records && columns
|
264
|
+
ellipsis_record = columns.each_with_object({}) { |col, record| record[col[:field]] = '...' }
|
265
|
+
truncated_records << ellipsis_record
|
266
|
+
end
|
267
|
+
records = truncated_records
|
229
268
|
end
|
230
269
|
|
231
270
|
# Apply max columns
|
@@ -244,12 +244,20 @@ module Poml
|
|
244
244
|
if File.directory?(full_path)
|
245
245
|
# Check if directory should be included
|
246
246
|
if !filter || entry.match?(Regexp.new(filter))
|
247
|
-
|
248
|
-
|
247
|
+
if current_depth + 1 < max_depth
|
248
|
+
# If we can go deeper, recurse and include subdirectories
|
249
|
+
sub_items = build_tree_structure(full_path, filter, max_depth, show_content, current_depth + 1)
|
249
250
|
items << {
|
250
251
|
name: "#{entry}/",
|
251
252
|
type: 'directory',
|
252
|
-
children: sub_items
|
253
|
+
children: sub_items || []
|
254
|
+
}
|
255
|
+
else
|
256
|
+
# At max depth, just show the directory without recursing
|
257
|
+
items << {
|
258
|
+
name: "#{entry}/",
|
259
|
+
type: 'directory',
|
260
|
+
children: []
|
253
261
|
}
|
254
262
|
end
|
255
263
|
end
|
@@ -505,4 +513,68 @@ module Poml
|
|
505
513
|
text.to_s.gsub('&', '&').gsub('<', '<').gsub('>', '>').gsub('"', '"')
|
506
514
|
end
|
507
515
|
end
|
516
|
+
|
517
|
+
# File component for reading and including file contents
|
518
|
+
class FileComponent < Component
|
519
|
+
def render
|
520
|
+
apply_stylesheet
|
521
|
+
|
522
|
+
src = get_attribute('src')
|
523
|
+
|
524
|
+
# Handle missing src attribute
|
525
|
+
unless src
|
526
|
+
return handle_error("no src specified")
|
527
|
+
end
|
528
|
+
|
529
|
+
# Resolve file path
|
530
|
+
file_path = resolve_file_path(src)
|
531
|
+
|
532
|
+
# Check if file exists
|
533
|
+
unless File.exist?(file_path)
|
534
|
+
return handle_error("file not found: #{src}")
|
535
|
+
end
|
536
|
+
|
537
|
+
# Read file content
|
538
|
+
begin
|
539
|
+
content = File.read(file_path, encoding: 'utf-8')
|
540
|
+
|
541
|
+
if xml_mode?
|
542
|
+
render_as_xml('file', content, { src: src })
|
543
|
+
else
|
544
|
+
content
|
545
|
+
end
|
546
|
+
rescue => e
|
547
|
+
handle_error("error reading file: #{e.message}")
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
private
|
552
|
+
|
553
|
+
def resolve_file_path(src)
|
554
|
+
# Handle absolute paths
|
555
|
+
return src if src.start_with?('/')
|
556
|
+
|
557
|
+
# Handle relative paths - try relative to source file first
|
558
|
+
if @context.source_path
|
559
|
+
base_path = File.dirname(@context.source_path)
|
560
|
+
candidate_path = File.join(base_path, src)
|
561
|
+
return candidate_path if File.exist?(candidate_path)
|
562
|
+
end
|
563
|
+
|
564
|
+
# Try relative to current working directory
|
565
|
+
candidate_path = File.join(Dir.pwd, src)
|
566
|
+
return candidate_path if File.exist?(candidate_path)
|
567
|
+
|
568
|
+
# Return the original path for final existence check
|
569
|
+
src
|
570
|
+
end
|
571
|
+
|
572
|
+
def handle_error(message)
|
573
|
+
if xml_mode?
|
574
|
+
render_as_xml('file-error', message)
|
575
|
+
else
|
576
|
+
"[File: #{message}]"
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
508
580
|
end
|
data/lib/poml/components.rb
CHANGED
data/lib/poml/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ghennadii Mirosnicenco
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-08-
|
10
|
+
date: 2025-08-19 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rexml
|