Module: Card::Loader

Defined in:
lib/card/loader.rb

Class Method Summary collapse

Class Method Details

.load_chunksObject



67
68
69
70
71
# File 'lib/card/loader.rb', line 67

def load_chunks
  mod_dirs.each do |mod|
    load_dir "#{mod}/chunk/*.rb"
  end
end

.load_layoutsObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/card/loader.rb', line 73

def load_layouts
  mod_dirs.inject({}) do |hash, mod|
    dirname = "#{mod}/layout"
    if File.exists? dirname
      Dir.foreach(dirname) do |filename|
        next if filename =~ /^\./
        hash[filename.gsub /\.html$/, ''] =
          File.read([dirname, filename] * '/')
      end
    end
    hash
  end
end

.load_modsObject



19
20
21
22
23
24
25
26
27
# File 'lib/card/loader.rb', line 19

def load_mods
  load_set_patterns
  load_formats
  load_sets

  if ENV['RAILS_ENV'] == 'development'
    update_machine_output_hack
  end
end

.mod_dirsObject



87
88
89
90
91
92
93
94
95
# File 'lib/card/loader.rb', line 87

def mod_dirs
  @@mod_dirs ||= begin
    Card.paths['mod'].existent.map do |dirname|
      Dir.entries(dirname).sort.map do |filename|
        "#{dirname}/#{filename}" if filename !~ /^\./
      end.compact
    end.flatten.compact
  end
end

.update_machine_output_hackObject



29
30
31
32
# File 'lib/card/loader.rb', line 29

def update_machine_output_hack
  update_script_output
  update_style_output
end

.update_script_outputObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/card/loader.rb', line 34

def update_script_output
  script = Card['*all+*script']
  return unless (mtime_output = script.machine_output_card.updated_at)
  ['wagn_mod.js.coffee', 'wagn.js.coffee',
   'script_card_menu.js.coffee'].each do |name|
    mtime_file = File.mtime(
      "#{Cardio.gem_root}/mod/03_machines/lib/javascript/#{name}"
    )
    if mtime_file > mtime_output
      script.update_machine_output
      break
    end
  end
end

.update_style_outputObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/card/loader.rb', line 49

def update_style_output
  style = Card['*all+*style']
  return unless (mtime_output = style.machine_output_card.updated_at)
  style.machine_input_card.item_cards.each do |i_card|
    next unless i_card.codename
    ['03_machines', '06_bootstrap'].each do |mod|
      style_dir = "#{Cardio.gem_root}/mod/#{mod}/lib/stylesheets"
      file_path = "#{style_dir}/#{i_card.codename}.scss"
      next unless File.exist? file_path
      mtime_file = File.mtime file_path
      if mtime_file > mtime_output
        style.update_machine_output
        break
      end
    end
  end
end