Class: Tipsy::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/tipsy/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ar, stdin) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
14
15
16
17
# File 'lib/tipsy/runner.rb', line 8

def initialize(ar, stdin)
  @args = [ar].flatten    
  cmd = args.first || "serve"
  cmd = "serve"  if ['', 'run', 's', 'serve'].include?(cmd)
  cmd = "create" if cmd == 'new'
  args.shift
  Tipsy::Site.configure!
  @site = Tipsy::Site.new
  send(:"#{cmd}")
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/tipsy/runner.rb', line 6

def args
  @args
end

#siteObject (readonly)

Returns the value of attribute site.



6
7
8
# File 'lib/tipsy/runner.rb', line 6

def site
  @site
end

Instance Method Details

#compileObject

Responsible for compiling the final site for deployment. This process will take the following steps:

  1. Copy files recursively from /public

  2. Compile javascripts, sprites, and css files into their respective directories within the compile folder

  3. Render all templates and place in their proper directories within the compile folder.



101
102
103
# File 'lib/tipsy/runner.rb', line 101

def compile
  Tipsy::Runners::Compiler.new(@args, @site)
end

#createObject

Generates a new site in the specified path.



87
88
89
# File 'lib/tipsy/runner.rb', line 87

def create
  Tipsy::Runners::Generator.new(args, @site)
end

#deployObject

Responsible for deploying a compiled site to a production server.



110
111
112
# File 'lib/tipsy/runner.rb', line 110

def deploy
  Tipsy::Runners::Deployer.new
end

#serveObject

Create an instance of Rack::Builder to serve the “static” site.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tipsy/runner.rb', line 24

def serve
  require 'tipsy/server'
  require 'tipsy/view'
  require 'rack'
  
  conf = Tipsy::Site.config
  missing_legacy_message  = "Rack::Legacy could not be loaded. Add it to your gemfile or set 'enable_php' to false in config.rb"
  missing_rewrite_message = "Rack::Rewrite could not be loaded. Add it to your gemfile or remove 'rewrite_rules' from config.rb"
  if conf.enable_php
    begin
      require 'rack-legacy'
      require 'tipsy/handler/php' 
    rescue LoadError
      puts missing_legacy_message
    end
  end
  
  app = Rack::Builder.new {
    use Rack::Reloader
    use Rack::ShowStatus
    
    unless conf.rewrite_rules.empty?
      begin
        require 'rack-rewrite'
        puts "Enabling Rack Rewrite"
        use Rack::Rewrite do
          conf.rewrite_rules.each do |pair|
            rewrite pair.first, pair.last
          end
        end
      rescue LoadError
        puts missing_rewrite_message
      end
    end
    
    if conf.enable_php
      begin
        puts "PHP Enabled"
        use Rack::Legacy::Php, conf.public_path
      rescue
      end
    end
    use Rack::ShowExceptions
    use Tipsy::Handler::StaticHandler, :root => conf.public_path, :urls => %w[/]
    run Rack::Cascade.new([
    	Rack::URLMap.new(Tipsy::Handler::AssetHandler.map!),
    	Tipsy::Server.new
    ])
  }.to_app
  
  conf    = Tipsy::Site.config
  options = {
    :Host => conf.address,
    :Port => conf.port
  }
  
  Tipsy::Server.run!(app, options)
end