Sha256: 9641176924a7203829762b5f41de4ae219267aadad0d1cebb7bf1dcd27996cf0

Contents?: true

Size: 1.84 KB

Versions: 5

Compression:

Stored size: 1.84 KB

Contents

include_set Abstract::Sources

class << self
  def included host_class
    track_mod_name host_class, caller
  end

  def track_mod_name host_class, caller
    host_class.mattr_accessor :file_content_mod_name
    host_class.file_content_mod_name = Card::Set.mod_name(caller)
  end
end

# FIXME: these should abstracted and configured on the types
# (same codes for `rake card:create:codefile`)

# @return [Array<String>, String] the name of file(s) to be loaded
def source_files
  case type_id
  when CoffeeScriptID then "#{codename}.js.coffee"
  when JavaScriptID   then "#{codename}.js"
  when CssID          then "#{codename}.css"
  when ScssID         then "#{codename}.scss"
  end
end

def source_dir
  case type_id
  when CoffeeScriptID, JavaScriptID then "lib/javascript"
  when CssID, ScssID then "lib/stylesheets"
  else
    "lib"
  end
end

def mod_path
  modname = file_content_mod_name
  if (match = modname.match(/^card-mod-(\w*)/))
    modname = match[1]
  end
  Cardio::Mod.dirs.path modname
end

def source_paths
  Array.wrap(source_files).map do |filename|
    ::File.join mod_path, source_dir, filename
  end
end

def content
  Array.wrap(source_paths).map do |path|
    if (source_path = find_file path)
      Rails.logger.debug "reading file: #{source_path}"
      ::File.read source_path
    end
  end.compact.join "\n"
end

format :html do
  view :input do
    "Content is stored in file and can't be edited."
  end

  view :file_size do
    "#{card.name}: #{number_to_human_size card.content.bytesize}"
  end

  def short_content
    fa_icon("exclamation-circle", class: "text-muted pr-2") +
      wrap_with(:span, "file", class: "text-muted")
  end

  def standard_submit_button
    multi_card_editor? ? super : ""
  end
end

def coffee_files files
  files.map { |f| "script_#{f}.js.coffee" }
end

def scss_files files
  files.map { |f| "style_#{f}.scss" }
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
card-mod-content-0.13.4 set/abstract/01_code_file.rb
card-mod-content-0.13.3 set/abstract/01_code_file.rb
card-mod-content-0.13.2 set/abstract/01_code_file.rb
card-mod-content-0.13.1 set/abstract/01_code_file.rb
card-mod-content-0.13.0 set/abstract/01_code_file.rb