trevl 0.1.0 → 0.2.0

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: 18b85bde0894ec3023141a8e20862d0bc2641ece9cab486b0743d765fdae45e3
4
- data.tar.gz: 57b043cd9f75abdd5a8a3b4f63276c9526c7893f059eaa7d9acd19d9c68de0df
3
+ metadata.gz: eec93861d586409e4fd6cd6c02dff9a6e06ab68c92b34a899eca5b5f6c6be4c7
4
+ data.tar.gz: 3dff7f729d56d1807f7bdf1c1f3bfc459f9c52b2226bf15edb6c40e3d9537ca0
5
5
  SHA512:
6
- metadata.gz: c06f1cffb20b1ea8185d89425395702a44c443f1f4928011876f8eccc5f04218a413c25edd610613abc35da88c9694b91a60304158f0b48a72239cdb1963d090
7
- data.tar.gz: 4224f7d0f8675a6de3ceca6c3665f9df884275b01d4efe835621b10e81bd4a0e0b7708651b7953908d6e1c39b875da0f4c4f27688d1d889c8c010ebf78c6c77b
6
+ metadata.gz: 0c1f5e72fd29d9c26825008279f30a01d9e45910b63044072fd61275e90f1f572e167c6344bfb2dfb75c299ef5cc4a69390ff8d3f56ea9c6e1373eb9774e1b59
7
+ data.tar.gz: f284d99524a6a8be3abe5b4644071eb1fd8cdbab8c7f5cf20d27039f77a2984fa3b93ba26249bdc8b1232c72393c690e73e3e25e6e7c3c110ac9820b82a2acc3
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <img src="assets/trendence-logo.svg" alt="Trendence" width="140" />
5
5
  </p>
6
6
 
7
- <h3 align="center">Write YAML, get Highcharts.</h3>
7
+ <h3 align="center">Write YAML, get Highcharts. Efficient assembly of dashboards on well-grounded rails.</h3>
8
8
 
9
9
  <p align="center">
10
10
  <a href="https://trevl.trendence.com">DSL Documentation</a> &middot;
@@ -63,7 +63,7 @@ Trevl.render(yaml)
63
63
  ## Installation
64
64
 
65
65
  ```ruby
66
- gem "trevl", github: "trendence/trevl"
66
+ gem "trevl"
67
67
  ```
68
68
 
69
69
  **Prerequisites:** Ruby >= 3.1, Node.js (`brew install node`) for computed fields.
@@ -33,7 +33,10 @@ module Trevl
33
33
  end
34
34
 
35
35
  # Applies postprocess JavaScript to the full dataset.
36
- def apply_postprocess(rows_by_ref_key, component, warnings)
36
+ # `raw_results`, when given, collects what the JavaScript actually
37
+ # returned per ref key, including a non-Array that gets discarded below.
38
+ # That is what tooling needs to explain a postprocess that did nothing.
39
+ def apply_postprocess(rows_by_ref_key, component, warnings, raw_results: nil)
37
40
  code = component["postprocess"]
38
41
  return rows_by_ref_key unless code.is_a?(String) && !code.strip.empty?
39
42
 
@@ -41,6 +44,7 @@ module Trevl
41
44
  js = "(function() { var $result = #{rows.to_json}; #{code.strip.chomp(";")}; return $result; })()"
42
45
  begin
43
46
  result = ExecJS.eval(js)
47
+ raw_results[rk] = result if raw_results
44
48
  if result.is_a?(Array)
45
49
  rows_by_ref_key[rk] = result
46
50
  else
@@ -6,7 +6,8 @@ require_relative "renderer/transform"
6
6
 
7
7
  module Trevl
8
8
  class Renderer
9
- attr_reader :component, :query_params, :data_sources, :inline_source, :raw_data, :warnings
9
+ attr_reader :component, :query_params, :data_sources, :inline_source, :raw_data, :warnings,
10
+ :postprocess_rows, :postprocess_raw_results
10
11
 
11
12
  def initialize(component_hash, query_params = {}, data_sources: {}, data: nil)
12
13
  @component = component_hash
@@ -92,7 +93,11 @@ module Trevl
92
93
  counts_before = rows_by_ref_key.transform_values(&:length)
93
94
 
94
95
  rows_by_ref_key = @transform.apply_computed_fields(rows_by_ref_key, payload_by_ref_key, component)
95
- rows_by_ref_key = @transform.apply_postprocess(rows_by_ref_key, component, @warnings)
96
+
97
+ raw_results = {}
98
+ rows_by_ref_key = @transform.apply_postprocess(rows_by_ref_key, component, @warnings, raw_results: raw_results)
99
+ @postprocess_raw_results = raw_results unless raw_results.empty?
100
+ @postprocess_rows = CoreExt::Hash.deep_dup(rows_by_ref_key)
96
101
 
97
102
  rows_by_ref_key.each do |key, rows|
98
103
  warn_postprocess_emptied(key, counts_before[key]) if rows.empty? && counts_before[key].to_i > 0
data/lib/trevl/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trevl
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trevl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Stammer