liquidum 1.1.0 → 1.1.1
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/liquidum/configuration.rb +26 -7
- data/lib/liquidum/liquid/filters/translate_filter.rb +6 -6
- data/lib/liquidum/liquid/liquid_helpers.rb +18 -20
- data/lib/liquidum/version.rb +1 -1
- data/liquidum.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a19fc1988722ecc75d48fdc1e25101679f91af1cc0de696118198d5a35d08b
|
4
|
+
data.tar.gz: fc6a6a5d26c79dc15fb0be0e9b0ec404b97387395d80221b3b38d2d0b86cbcbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 384e81ad24db742d2995fa4af3bf3891f4a6d10ded6f47c43a05a9d708409e1297f07749264ec5c845711b7fc8b63d2b2f1d3c6ce464835d4450b6716428699b
|
7
|
+
data.tar.gz: 6dd9b4c3eb08256f02a5c92cb1ada34937606bd5154497c7618a8355c06b2ca4072e3e206e7a2d048726541de3f77be30bc0fe963af78a7c23cf0fdd27f7469a
|
@@ -1,10 +1,20 @@
|
|
1
1
|
module Liquidum
|
2
2
|
module Options
|
3
3
|
module ClassMethods
|
4
|
-
def option(name, default: nil)
|
5
|
-
|
4
|
+
def option(name, default: nil, proc: false)
|
5
|
+
attr_writer(name)
|
6
|
+
schema[name] = {default: default, proc: proc}
|
6
7
|
|
7
|
-
schema[name]
|
8
|
+
if schema[name][:proc]
|
9
|
+
define_method(name) do |*params|
|
10
|
+
value = instance_variable_get(:"@#{name}")
|
11
|
+
instance_exec(*params, &value)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
define_method(name) do
|
15
|
+
instance_variable_get(:"@#{name}")
|
16
|
+
end
|
17
|
+
end
|
8
18
|
end
|
9
19
|
|
10
20
|
def schema
|
@@ -13,8 +23,8 @@ module Liquidum
|
|
13
23
|
end
|
14
24
|
|
15
25
|
def set_defaults!
|
16
|
-
self.class.schema.each do |name,
|
17
|
-
instance_variable_set(:"@#{name}", default)
|
26
|
+
self.class.schema.each do |name, options|
|
27
|
+
instance_variable_set(:"@#{name}", options[:default])
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
@@ -26,13 +36,22 @@ module Liquidum
|
|
26
36
|
class Configuration
|
27
37
|
include Options
|
28
38
|
|
29
|
-
option :logger, default: -> { Logger.new($stdout).tap { |l| l.level = Logger::INFO } }
|
39
|
+
option :logger, default: -> { Logger.new($stdout).tap { |l| l.level = Logger::INFO } }, proc: true
|
30
40
|
option :liquidum_file_system, default: "Liquidum::LiquidumFileSystem"
|
31
|
-
|
41
|
+
attr_writer :i18n_store
|
32
42
|
|
33
43
|
def initialize
|
44
|
+
@i18n_store = ->(context, block) {}
|
34
45
|
set_defaults!
|
35
46
|
end
|
47
|
+
|
48
|
+
def i18n_store(context, &block)
|
49
|
+
old_i18n_backend = I18n.backend
|
50
|
+
I18n.backend = instance_exec(context, &@i18n_store)
|
51
|
+
yield
|
52
|
+
ensure
|
53
|
+
I18n.backend = old_i18n_backend
|
54
|
+
end
|
36
55
|
end
|
37
56
|
|
38
57
|
module Configurable
|
@@ -19,27 +19,27 @@ module TranslateFilter
|
|
19
19
|
result = nil
|
20
20
|
|
21
21
|
Liquidum.config.i18n_store(@context) do |obj|
|
22
|
-
locale = options.delete(
|
22
|
+
locale = options.delete("locale")
|
23
23
|
|
24
24
|
key = input
|
25
25
|
scope = nil
|
26
26
|
|
27
|
-
if key.start_with?(
|
27
|
+
if key.start_with?(".")
|
28
28
|
key = input[1..-1]
|
29
|
-
scope = obj.translation_scope
|
29
|
+
scope = obj.translation_scope if obj.respond_to?(:translation_scope)
|
30
30
|
end
|
31
31
|
|
32
|
-
result = I18n.t(key, locale: locale, scope: scope, cascade: {
|
32
|
+
result = I18n.t(key, locale: locale, scope: scope, cascade: {skip_root: false},
|
33
33
|
**options.symbolize_keys)
|
34
34
|
if result
|
35
35
|
result = I18n::Backend::Simple.new.send(:interpolate, I18n.locale, result,
|
36
|
-
|
36
|
+
options.symbolize_keys)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
result
|
41
41
|
end
|
42
|
-
|
42
|
+
alias_method :t, :translate
|
43
43
|
end
|
44
44
|
|
45
45
|
Liquid::Template.register_filter(TranslateFilter)
|
@@ -24,7 +24,7 @@ module Liquidum
|
|
24
24
|
|
25
25
|
# Return named argument
|
26
26
|
def arg(name)
|
27
|
-
raise
|
27
|
+
raise "No @context set" unless @context
|
28
28
|
|
29
29
|
attr = @args.find { |a| a[:attr] == name.to_s }
|
30
30
|
return unless attr
|
@@ -39,7 +39,7 @@ module Liquidum
|
|
39
39
|
# Returns the first argument - usually reserved for literal or quoted values, not for attribute value pairs
|
40
40
|
# When the first attribute is a pair, it will return nil
|
41
41
|
def argv1
|
42
|
-
raise
|
42
|
+
raise "No @context set" unless @context
|
43
43
|
|
44
44
|
argv1 = @args[0]
|
45
45
|
return unless argv1
|
@@ -53,7 +53,7 @@ module Liquidum
|
|
53
53
|
|
54
54
|
# Returns the standalone arguments
|
55
55
|
def sargs
|
56
|
-
raise
|
56
|
+
raise "No @context set" unless @context
|
57
57
|
|
58
58
|
@args.slice(1..-1).select { |a| a.key?(:quoted) || a.key?(:literal) }.map do |a|
|
59
59
|
if a.key? :quoted
|
@@ -66,7 +66,7 @@ module Liquidum
|
|
66
66
|
|
67
67
|
# Returns the attribute-value-pair arguments as a hash
|
68
68
|
def attr_args
|
69
|
-
raise
|
69
|
+
raise "No @context set" unless @context
|
70
70
|
|
71
71
|
result = {}
|
72
72
|
@args.select { |a| a.key?(:value) || a.key?(:lvalue) || a.key?(:svalue) }.map do |a|
|
@@ -89,7 +89,7 @@ module Liquidum
|
|
89
89
|
# @return [String]
|
90
90
|
def attr_str(attr, value, default = nil)
|
91
91
|
v = value || default
|
92
|
-
v.present? ? " #{attr}=\"#{v}\"" :
|
92
|
+
v.present? ? " #{attr}=\"#{v}\"" : ""
|
93
93
|
end
|
94
94
|
|
95
95
|
def attrs_str(*attrs, reject: [])
|
@@ -111,20 +111,18 @@ module Liquidum
|
|
111
111
|
|
112
112
|
# For use with forms and inputs
|
113
113
|
def input(purpose, name)
|
114
|
-
form_model
|
115
|
-
form_class_name = lookup(@context,
|
116
|
-
|
117
|
-
# binding.pry if name == 'postal_code'
|
114
|
+
form_model = lookup(@context, "form.model")
|
115
|
+
form_class_name = lookup(@context, "form.class_name")
|
118
116
|
|
119
117
|
# order[order_lines_attributes][xxxx][product_name]
|
120
118
|
#
|
121
119
|
# order[order_attributes]_[lines_attributes][][product_name]
|
122
120
|
|
123
|
-
parts = @context.scopes.select { |scope| scope.key?
|
124
|
-
if scope[
|
125
|
-
scope[
|
121
|
+
parts = @context.scopes.select { |scope| scope.key? "form" }.map do |scope|
|
122
|
+
if scope["form"].attribute
|
123
|
+
scope["form"].attribute.to_s.gsub(/([a-z\-\_]+)/) { "[#{Regexp.last_match(1)}_attributes]" }.gsub(/\[\]$/, "[#{SecureRandom.uuid}]")
|
126
124
|
else
|
127
|
-
scope[
|
125
|
+
scope["form"].class_name.underscore.gsub("/", "_")
|
128
126
|
end
|
129
127
|
end
|
130
128
|
parts = parts.unshift("[#{name}]").reverse
|
@@ -133,7 +131,7 @@ module Liquidum
|
|
133
131
|
|
134
132
|
case purpose
|
135
133
|
when :id
|
136
|
-
parts.join(
|
134
|
+
parts.join("_").gsub("][", "_").tr("][", "")
|
137
135
|
when :value
|
138
136
|
# This is executed on the drop, drops provide the values for the form
|
139
137
|
form_model.send(name.to_sym)
|
@@ -141,23 +139,23 @@ module Liquidum
|
|
141
139
|
# The original class's name dictates the name of the fields
|
142
140
|
parts.first + parts.slice(1..-1).join
|
143
141
|
when :error
|
144
|
-
parts.slice(1..-1).join(
|
142
|
+
parts.slice(1..-1).join(".")
|
145
143
|
when :checked
|
146
|
-
|
144
|
+
"checked" if (input(:value, name) ? 1 : 0) == 1
|
147
145
|
end
|
148
146
|
end
|
149
147
|
|
150
148
|
# Returns the path for the input from the main form, say: origin.contact_name
|
151
149
|
def path_for_input(name)
|
152
|
-
parts = @context.scopes.select { |scope| scope.key?
|
153
|
-
scope[
|
150
|
+
parts = @context.scopes.select { |scope| scope.key? "form" }.select { |scope| scope["form"].attribute }.map do |scope|
|
151
|
+
scope["form"].attribute
|
154
152
|
end
|
155
153
|
parts = parts.unshift(name.to_s).reverse
|
156
|
-
parts.join(
|
154
|
+
parts.join(".")
|
157
155
|
end
|
158
156
|
|
159
157
|
def real_object_from_drop(drop)
|
160
|
-
drop.instance_variable_get(
|
158
|
+
drop.instance_variable_get("@object")
|
161
159
|
end
|
162
160
|
end
|
163
161
|
end
|
data/lib/liquidum/version.rb
CHANGED
data/liquidum.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_runtime_dependency("i18n", ["~> 1.8"])
|
29
29
|
spec.add_runtime_dependency("kramdown", ["~> 2.1"])
|
30
30
|
spec.add_runtime_dependency("kramdown-parser-gfm", ["~> 1.0"])
|
31
|
-
spec.add_runtime_dependency("liquid", ["
|
31
|
+
spec.add_runtime_dependency("liquid", ["~> 5.1"])
|
32
32
|
spec.add_runtime_dependency("parslet", [">= 0"])
|
33
33
|
spec.add_runtime_dependency("pg", [">= 0"])
|
34
34
|
spec.add_runtime_dependency("rails", [">= 5.2"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquidum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom de Grunt
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: liquid
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 5.1
|
89
|
+
version: '5.1'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 5.1
|
96
|
+
version: '5.1'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: parslet
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|