Commit 6d68782d by ivan Lan

Separate the product & series views template & Fix bug cause for the new json column changes

parent cea424ab
......@@ -2,18 +2,23 @@ module Shotengai
class Harray < Array
class << self
def encode hash
Harray.new(
hash.map {|key, val| { 'key' => key, 'val' => val } }
Harray.new(
if hash.is_a?(Hash)
hash.map {|key, val| { 'key' => key, 'val' => val } }
else
Array(hash)
end
)
end
def decode harray
harray && Harray.new(harray).decode
Harray.encode(harray).decode
end
end
# def initialize
# def initialize *arg, &block
# # Add some validations
# BUT HOW?
# end
def keys
......
......@@ -11,7 +11,7 @@ module Shotengai
class_eval %Q{
def #{column}= val
raise Shotengai::WebError.new('#{column} 必须是个 Array', -1 , 401) unless val.nil? || Array === val
super(#{decode} ? Harray.decode(val) : val)
super(#{decode} ? Shotengai::Harray.decode(val) : val)
end
}
end
......@@ -38,7 +38,7 @@ module Shotengai
class_eval %Q{
def #{key}
{
template: #{template},
template: Shotengai::Harray.encode(#{template}).keys,
value: #{value},
}
end
......@@ -51,7 +51,7 @@ module Shotengai
end
keys.each do |key|
value = value_in_template ? "#{key}_template.decode" : "#{key}_value"
value = value_in_template ? "Shotengai::Harray.decode(#{key}_template)" : "#{key}_value"
self.template_with_value key, value: value
end
end
......@@ -69,11 +69,11 @@ module Shotengai
raise Shotengai::WebError.new('#{chimera} 必须是个 Hash', -1 , 401) unless val.nil? || Hash === val
write_attribute(:#{column}, val)
end
# TODO: WARNING: 这里也 没有继承 之前方法的解析
def #{column}_before_implant
#{column}
end
# WARNING: 默认值为 {}
define_method('#{column}') do
#{chimera}['#{as}'] || {}
end
......
......@@ -40,7 +40,7 @@ module Shotengai
harray_accessor :info_template, :detail_info_template
harray_accessor :spec_value, :remark_value, decode: true
template_with_value_getters :info, value_in_template: true
template_with_value_getters :info, :detail_info, value_in_template: true
template_with_value_getters :spec, :remark, delegate_template_to: :product
# full_info_template: { optional: d, detail: detail_info_template }
......
......@@ -38,7 +38,7 @@ module Shotengai
validate :check_remark_value, unless: :remark_template_empty?
validates :count, numericality: { only_integer: true, greater_than: 0 }
template_with_value_getters :spec, :remark, :info, delegate_template_to: :series
template_with_value_getters :spec, :remark, :info, :detail_info, delegate_template_to: :series
column_has_implants :meta, implants: ['product', 'series'], as: :snapshot
column_has_implants :info_value, implants: ['detail'], as: :snapshot
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment