mirror of
https://github.com/usetrmnl/trmnl-liquid.git
synced 2026-04-29 13:43:18 -07:00
Merge pull request #1 from usetrmnl/parse_json_filter
parse_json filter
This commit is contained in:
@@ -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
@@ -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)
|
||||
|
||||
@@ -69,6 +69,10 @@ module TRMNL
|
||||
JSON.generate(obj)
|
||||
end
|
||||
|
||||
def parse_json(obj)
|
||||
JSON.parse(obj)
|
||||
end
|
||||
|
||||
def sample(array) = array.sample
|
||||
|
||||
private
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user