Merge pull request #1 from usetrmnl/parse_json_filter

parse_json filter
This commit is contained in:
Ryan Kulp
2025-08-20 13:22:54 -04:00
committed by GitHub
4 changed files with 11 additions and 4 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ gem "rspec"
# optional peer dependencies
gem "i18n", "~> 1.14"
gem "rails-i18n", "~> 8.0"
gem "trmnl-i18n", github: "usetrmnl/trmnl-i18n", branch: "main"
gem "trmnl-i18n", github: "usetrmnl/trmnl-i18n", branch: "main"
+1 -1
View File
@@ -9,7 +9,7 @@ GIT
PATH
remote: .
specs:
trmnl-liquid (0.1.0)
trmnl-liquid (0.2.0)
actionview (~> 8.0)
liquid (~> 5.6)
redcarpet (~> 3.6)
+4
View File
@@ -69,6 +69,10 @@ module TRMNL
JSON.generate(obj)
end
def parse_json(obj)
JSON.parse(obj)
end
def sample(array) = array.sample
private
+5 -2
View File
@@ -79,9 +79,12 @@ describe TRMNL::Liquid::Filters do
expect_render('{{ data | json }}', '[{"a":1,"b":"c"},"d"]', 'data' => [{ 'a' => 1, 'b' => 'c' }, 'd'])
end
it 'supports parse_json' do
expect_render('{{ data | parse_json }}', [{ 'a' => 1, 'b' => 'c' }, 'd'].to_json, 'data' => '[{"a":1,"b":"c"},"d"]'.to_json)
end
it 'supports sample' do
expect(["1", "2", "3", "4", "5"].any? { |str| str == service.parse('{{ data | split: "," | sample }}').render({ "data" => "1,2,3,4,5" }) })
expect(["cat", "dog"].any? { |str| str == service.parse('{{ data | split: "," | sample }}').render({ "data" => "cat,dog" }) })
end
end
end