Sha256: cf7ecd6d6d83e4e85db877f77a711a0c7dd500a05b71431f1c155bc956c0553a

Contents?: true

Size: 660 Bytes

Versions: 4

Compression:

Stored size: 660 Bytes

Contents

# include_set Abstract::Pointer

event :validate_json, :validate, on: :save, changed: :content do
  check_json_syntax if content.present?
end

def check_json_syntax
  parse_content
rescue JSON::ParserError => e
  errors.add t(:format_invalid_json), e.message.sub(/^\d+: /, "").to_s
end

def parse_content
  JSON.parse content
end

def item_names _args={}
  parse_content.keys.map(&:to_name)
end

def item_values
  parse_content.values
end

def item_value name
  parse_content[name]
end

format :html do
  view :core do
    process_content ::CodeRay.scan(_render_raw, :json).div
  end

  def input_type
    :ace_editor
  end

  def ace_mode
    :json
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
card-mod-format-0.11.7 set/type/json.rb
card-mod-format-0.11.6 set/type/json.rb
card-mod-format-0.11.5 set/type/json.rb
card-mod-format-0.11.4 set/type/json.rb