Sha256: b97a178bf26ca85fbfd8d30910e35986f2ac496b505fb02d7b404fac21673160

Contents?: true

Size: 559 Bytes

Versions: 6

Compression:

Stored size: 559 Bytes

Contents

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 tr(:invalid_json), e.message.sub(/^\d+: /, "").to_s
end

def parse_content
  JSON.parse content
end

def item_names _args={}
  parse_content.keys
end

def item_values
  parse_content.values
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

6 entries across 6 versions & 1 rubygems

Version Path
card-1.100.0 mod/basic_types/set/type/json.rb
card-1.99.6 mod/basic_types/set/type/json.rb
card-1.99.5 mod/basic_types/set/type/json.rb
card-1.99.4 mod/basic_types/set/type/json.rb
card-1.99.3 mod/basic_types/set/type/json.rb
card-1.99.2 mod/basic_types/set/type/json.rb