Sha256: 76c1c037a02435bc64d04a6e369560b11c89452a2888028b86d518d7e3b66d44

Contents?: true

Size: 669 Bytes

Versions: 12

Compression:

Stored size: 669 Bytes

Contents

require "coderay"

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
  content.blank? ? "" : 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

12 entries across 12 versions & 1 rubygems

Version Path
card-mod-format-0.18.1 set/type/json.rb
card-mod-format-0.18.0 set/type/json.rb
card-mod-format-0.17.0 set/type/json.rb
card-mod-format-0.16.0 set/type/json.rb
card-mod-format-0.15.6 set/type/json.rb
card-mod-format-0.15.5 set/type/json.rb
card-mod-format-0.15.4 set/type/json.rb
card-mod-format-0.15.3 set/type/json.rb
card-mod-format-0.15.2.pre1 set/type/json.rb
card-mod-format-0.15.1.1 set/type/json.rb
card-mod-format-0.15.1 set/type/json.rb
card-mod-format-0.15.0 set/type/json.rb