diff --git a/Gemfile b/Gemfile index 509316c1..d7c005ff 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ end gemspec gem "base64" +gem "webrick" group :benchmark, :test do gem 'benchmark-ips' diff --git a/example/server/example_servlet.rb b/example/server/example_servlet.rb index d2d4fd6a..595fd040 100644 --- a/example/server/example_servlet.rb +++ b/example/server/example_servlet.rb @@ -20,7 +20,7 @@ end class Servlet < LiquidServlet def index - { 'date' => Time.now } + { 'date' => Time.now, 'products' => products_list } end def products @@ -29,11 +29,42 @@ class Servlet < LiquidServlet private + class Name < Liquid::Drop + attr_reader :raw, :origin + + def initialize(raw, origin) + super() + @raw = raw + @origin = origin + end + end + + class Price < Liquid::Drop + attr_reader :value, :unit + + def initialize(value, unit = 'USD') + super() + @value = value + @unit = unit + end + end + + class Product < Liquid::Drop + attr_reader :name, :price, :description + + def initialize(name, origin, price, description) + super() + @name = Name.new(name, origin) + @price = Price.new(price) + @description = description + end + end + def products_list [ - { 'name' => 'Arbor Draft', 'price' => 39900, 'description' => 'the *arbor draft* is a excellent product' }, - { 'name' => 'Arbor Element', 'price' => 40000, 'description' => 'the *arbor element* rocks for freestyling' }, - { 'name' => 'Arbor Diamond', 'price' => 59900, 'description' => 'the *arbor diamond* is a made up product because im obsessed with arbor and have no creativity' } + { 'name' => 'Alpine jacket', 'price' => { 'value' => 30000, 'unit' => 'USD' }, 'description' => 'the *alpine jacket* is a excellent product' }, + { 'name' => 'Mountain boots', 'price' => { 'value' => 40000, 'unit' => 'BRL' }, 'description' => 'the *mountain boots* are perfect for hiking' }, + { 'name' => 'Safety helmet', 'price' => { 'value' => 10000, 'unit' => 'USD' }, 'description' => 'the *safety helmet* provides essential protection for winter sports' } ] end diff --git a/example/server/templates/index.liquid b/example/server/templates/index.liquid index 4872aa84..75bff570 100644 --- a/example/server/templates/index.liquid +++ b/example/server/templates/index.liquid @@ -1,6 +1,71 @@ -
Hello world!
+{% # theme-check-disable UnknownFilter, UndefinedObject %} + + + + +It is {{date}}
+
+ {% assign product = products | find: "name", "Mountain boots" %}
+ {{ product.name }} - {{ product.price.value }}
+
+ {% assign product = products | find: "price.unit", "USD" %}
+ {{ product.name }} - {{ product.price.value }}
+
+
+
+ {% assign index = products | find_index: "name", "Mountain boots" %}
+ {{ index }}
+
+
+
+ {{ products | has: "name", "Mountain boots" }}
+
-Check out the Products screen
+
+ {{ products | map: "name" | join: ", " }}
+ {{ products | reject: "name", "Mountain boots" | map: "name" | join: ", " }}
+
+
+
+