Sha256: 48395873bcbed137436e92188b2cdeb217c0eaface0b754547089bdbc5086ea4

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

# -*- encoding : utf-8 -*-

require "uglifier"

def self.included host_class
  host_class.include_set Abstract::Machine
  host_class.include_set Abstract::MachineInput

  host_class.machine_input { standard_machine_input }
  host_class.store_machine_output filetype: "js"
end

def standard_machine_input
  js = format(:js)._render_core
  js = compress_js js if compress_js?
  comment_with_source js
end

def comment_with_source js
  "//#{name}\n#{js}"
end

def compress_js input
  Uglifier.compile input
rescue => e
  # CoffeeScript is compiled in a view
  # If there is a CoffeeScript syntax error we get the rescued view here
  # and the error that the rescued view is no valid Javascript
  # To get the original error we have to refer to Card::Error.current
  raise Card::Error, compression_error_message(e)
end

def compression_error_message e
  if Card::Error.current
    Card::Error.current.message
  else
    "JavaScript::SyntaxError (#{name}): #{e.message}"
  end
end

def compress_js?
  !Rails.env.development?
end

def clean_html?
  false
end

format do
  def chunk_list  # turn off autodetection of uri's
    :nest_only
  end

  # def default_nest_view
  #   :raw
  # end
end

format :html do
  def editor
    :ace_editor
  end

  def ace_mode
    :javascript
  end

  view :content_changes do |args|
    wrap_with(:pre) { super args }
  end

  view :core do
    script = card.format(:js).render_core
    process_content highlight(script)
  end

  def highlight script
    ::CodeRay.scan(script, :js).div
  end
end

def diff_args
  { diff_format: :text }
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
card-1.94.1 mod/machines/set/abstract/script.rb
card-1.94.0 mod/machines/set/abstract/script.rb
card-1.93.13 mod/machines/set/abstract/script.rb
card-1.93.12 mod/machines/set/abstract/script.rb
card-1.93.11 mod/machines/set/abstract/script.rb
card-1.93.10 mod/machines/set/abstract/script.rb
card-1.93.9 mod/machines/set/abstract/script.rb
card-1.93.8 mod/machines/set/abstract/script.rb
card-1.93.7 mod/machines/set/abstract/script.rb
card-1.93.6 mod/machines/set/abstract/script.rb
card-1.93.5 mod/machines/set/abstract/script.rb
card-1.93.4 mod/machines/set/abstract/script.rb
card-1.93.3 mod/machines/set/abstract/script.rb
card-1.93.2 mod/machines/set/abstract/script.rb
card-1.93.1 mod/machines/set/abstract/script.rb
card-1.93.0 mod/machines/set/abstract/script.rb