Class: Cup::CommandLine

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/cup/command_line.rb

Defined Under Namespace

Classes: Helper

Instance Method Summary collapse

Instance Method Details

#buildObject



170
171
172
# File 'lib/cup/command_line.rb', line 170

def build
  Cup.build! :cli => self
end

#concatenateObject



175
176
177
# File 'lib/cup/command_line.rb', line 175

def concatenate
  $stdout.puts Cup.concatenate!
end

#create(name) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/cup/command_line.rb', line 131

def create(name)

  unless /^[\w-]+$/ =~ name
    raise "#{name} is not a valid filename (letters, numbers, underscore and dashes only)"
  end

  helper = Helper.new(name)

  if Dir.exists? helper.root
    say_status :halted, "Cannot cup '#{name}'. A directory of that name already exists", :red
    return
  end

  empty_directory helper.root
  helper.standard_directories.each {|dir| empty_directory dir}

  create_file helper.cupfile, helper.cupfile_default_content(name)

  create_file helper.licence_file, helper.get_licence

  jquery = helper.get_jquery

  if jquery
    say_status(:downloaded, "#{Helper::JasmineStandaloneDistributionURL}", :green)
    create_file helper.jquery_file, jquery
  else
    say_status(:failed, "download #{Helper::JQueryURL}", :red)
  end

  if helper.download_jasmine
    say_status(:downloaded, "#{Helper::JasmineStandaloneDistributionURL} and unpacked into vendor", :green)
  else
    say_status(:failed, "download/unpack #{Helper::JasmineStandaloneDistributionURL}", :red)
  end

  create_file helper.extra_matchers_file, helper.get_extra_matchers
end

#minifyObject



180
181
182
# File 'lib/cup/command_line.rb', line 180

def minify
  $stdout.puts Cup.minify!
end

#rackupObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/cup/command_line.rb', line 203

def rackup

  helper = pwd_helper

  return no_cupfile unless helper.cupfile?

  create_file helper.rackup_file, <<-CONFIG_RU
require 'rubygems' # for ruby 1.8.x
require 'rack'
require 'cup/server/app'

run Cup::Server::App
CONFIG_RU
end

#server(port = 5555) ⇒ Object



185
186
187
188
189
190
191
192
193
194
# File 'lib/cup/command_line.rb', line 185

def server(port=5555)

  helper = pwd_helper

  return no_cupfile unless helper.cupfile?

  say(shell.set_color "cup server for '#{Cup.cup_name}' starting on port #{port}", :cyan, true)
  Cup::Server::App.set :port => port
  Cup::Server::App.run!
end

#versionObject



197
198
199
200
# File 'lib/cup/command_line.rb', line 197

def version
  say("#{Cup.cup_name} v#{Cup.version}", :cyan) if File.exist?('Cupfile')
  say("cup v#{Cup::VERSION}")
end