Module: Card::Set::Abstract::CodeFile

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb,
card/tmpsets/set/mod006-card-mod-content/abstract/code_file.rb

Overview

Set: Abstract (CodeFile)

Defined Under Namespace

Modules: HtmlFormat

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.included(host_class) ⇒ Object



10
11
12
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 10

def included host_class
  track_mod_name host_class, caller
end

.source_locationObject



7
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-content/set/abstract/code_file.rb"; end

.track_mod_name(host_class, caller) ⇒ Object



14
15
16
17
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 14

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

Instance Method Details

#coffee_files(files) ⇒ Object



101
102
103
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 101

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

#contentObject



73
74
75
76
77
78
79
80
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 73

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

#existing_source_pathsObject



63
64
65
66
67
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 63

def existing_source_paths
  Array.wrap(source_files).map do |filename|
    find_file(filename)
  end.compact
end

#find_file(filename) ⇒ Object



42
43
44
45
46
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 42

def find_file filename
  File.join(mod_path, source_dir, filename).tap do |file_path|
    return nil if unknown_file? filename, file_path
  end
end

#mod_pathObject



48
49
50
51
52
53
54
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 48

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

#scss_files(files) ⇒ Object



105
106
107
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 105

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

#source_changed?(since:) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 69

def source_changed? since:
  existing_source_paths.any? { |path| ::File.mtime(path) > since }
end

#source_dirObject



33
34
35
36
37
38
39
40
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 33

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

#source_filesArray<String>, String

Returns the name of file(s) to be loaded.

Returns:

  • (Array<String>, String)

    the name of file(s) to be loaded



24
25
26
27
28
29
30
31
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 24

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

#unknown_file?(filename, file_path) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'card/tmpsets/set/mod007-card-mod-content/abstract/code_file.rb', line 56

def unknown_file? filename, file_path
  return false if File.exist? file_path

  Rails.logger.info "couldn't locate file #{filename} at #{file_path}"
  true
end