Class: Frontsau::ThorApp

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/frontsau/thor_app.rb

Instance Method Summary collapse

Instance Method Details

#cleanObject



41
42
43
44
45
# File 'lib/frontsau/thor_app.rb', line 41

def clean
  Dir[Frontsau.config[:assets][:path]+"/*"].each do |f|
    remove_file f
  end
end

#compileObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/frontsau/thor_app.rb', line 7

def compile
  say "Dumping assets:"
  inside Frontsau.assets_path do
    paths = Frontsau.sprockets.compilable_paths
    manifest = {}
    p = ProgressBar.create(
        total: paths.count,
        format: "   %p% | %B"
    )
    paths.each do |path|
      p.increment
      begin
        asset = Frontsau.sprockets[path]
        data = asset.to_s
        create_file path, data, force: true, verbose: false
        manifest[path] = {
          digest: asset.digest,
          modified: asset.mtime
        }
      rescue Exception => e
        say ""
        say ""
        say "#{e.class.name} ", :red
        say "#{e.message}"
        say ""
        say ""
      end
    end
    say ""
    create_file "manifest.json", JSON.pretty_generate(manifest), force: true
  end
end

#debug(what = "all") ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/frontsau/thor_app.rb', line 69

def debug what = "all"
  puts ""
  if what == "all"
    Frontsau.sprockets.each_logical_path do |path|
      puts "  #{path}"
    end
  elsif
    Frontsau.sprockets.compilable_paths.each do |path|
      puts "  #{path}"
    end
  end
  puts ""
end

#haml(input) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/frontsau/thor_app.rb', line 105

def haml input
  if !File.exist? input
    raise "Input file does not exist!"
  end
  path = File.dirname input
  name = File.basename input, '.haml'
  tool_root = File.dirname(File.dirname(File.dirname(__FILE__)))
  cmd = File.join(tool_root,"bin/frontsau-phaml-compiler")
  html = `#{cmd} '#{input}'`
  output = File.join(path,"#{name}.php")
  File.write output, html
end

#serverObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/frontsau/thor_app.rb', line 84

def server
  app = Rack::Builder.new do
    use Rack::CommonLogger
    use Rack::ShowExceptions
    use Rack::Cors do
      allow do
        origins '*'
        resource '*'
      end
    end
    map "/" do
      run Frontsau::Assets::Rack.new
    end
    map "/#{Frontsau.config[:assets][:path]}" do
      run Frontsau.sprockets
    end
  end
  Rack::Handler::WEBrick.run app, :Port => 9292
end

#watchObject



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

def watch
  compile
  say "Watching for asset changes:"
  Frontsau::Assets::Watcher.new do |path|
    begin
      asset = Frontsau.sprockets[path]
      create_file path, asset.to_s, force: true, verbose: true
    rescue Exception => e
      say ""
      say ""
      say "#{e.class.name} ", :red
      say "#{e.message}"
      say ""
      say ""
    end
  end
end