Module: Card::Set::Abstract::CodeFile
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod003-core/abstract/code_file.rb
Overview
Set: Abstract (CodeFile)
Defined Under Namespace
Modules: HtmlFormat
Constant Summary
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Class Method Summary collapse
Instance Method Summary collapse
- #coffee_files(files) ⇒ Object
- #content ⇒ Object
- #existing_source_paths ⇒ Object
- #find_file(filename) ⇒ Object
- #scss_files(files) ⇒ Object
- #source_changed?(since:) ⇒ Boolean
- #source_dir ⇒ Object
-
#source_files ⇒ Array<String>, String
The name of file(s) to be loaded.
Methods included from Card::Set
Methods included from I18nScope
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, #ensure_set, #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
Class Method Details
.included(host_class) ⇒ Object
8 9 10 11 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 8 def self.included host_class host_class.mattr_accessor :file_content_mod_name host_class.file_content_mod_name = Card::Set.mod_name(caller) end |
.source_location ⇒ Object
7 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/core/set/abstract/code_file.rb"; end |
Instance Method Details
#coffee_files(files) ⇒ Object
83 84 85 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 83 def coffee_files files files.map { |f| "script_#{f}.js.coffee" } end |
#content ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 55 def content Array.wrap(source_files).map do |filename| if (source_path = find_file filename) Rails.logger.info "reading file: #{source_path}" File.read source_path end end.compact.join "\n" end |
#existing_source_paths ⇒ Object
45 46 47 48 49 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 45 def existing_source_paths Array.wrap(source_files).map do |filename| find_file(filename) end.compact end |
#find_file(filename) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 35 def find_file filename mod_path = Card::Mod.dirs.path file_content_mod_name file_path = File.join(mod_path, source_dir, filename) unless File.exist?(file_path) Rails.logger.info "couldn't locate file #{filename} at #{file_path}" return nil end file_path end |
#scss_files(files) ⇒ Object
87 88 89 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 87 def scss_files files files.map { |f| "style_#{f}.scss" } end |
#source_changed?(since:) ⇒ Boolean
51 52 53 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 51 def source_changed? since: existing_source_paths.any? { |path| ::File.mtime(path) > since } end |
#source_dir ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 26 def source_dir case type_id when CoffeeScriptID, JavaScriptID then "lib/javascript" when CssID, ScssID then "lib/stylesheets" else "lib" end end |
#source_files ⇒ Array<String>, String
Returns the name of file(s) to be loaded.
17 18 19 20 21 22 23 24 |
# File 'tmpsets/set/mod003-core/abstract/code_file.rb', line 17 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 |