Module: Frank

Extended by:
Upgrades
Defined in:
lib/frank.rb,
lib/frank.rb,
lib/frank/cli.rb,
lib/frank/base.rb,
lib/frank/lorem.rb,
lib/frank/rescue.rb,
lib/frank/compile.rb,
lib/frank/publish.rb,
lib/frank/version.rb,
lib/frank/settings.rb,
lib/frank/upgrades.rb,
lib/frank/tilt_setup.rb,
lib/frank/publish/ftp.rb,
lib/frank/publish/scp.rb,
lib/frank/publish/base.rb,
lib/frank/publish/sftp.rb,
lib/frank/publish/ftptls.rb,
lib/frank/template_helpers.rb,
lib/frank/middleware/imager.rb,
lib/frank/middleware/statik.rb,
lib/frank/publish/shell_scp.rb,
lib/frank/middleware/refresh.rb

Overview

relay

Defined Under Namespace

Modules: Middleware, Publish, Render, Rescue, TemplateHelpers, Upgrades Classes: Base, CLI, Compile, ConfigError, HamlTemplate, Lorem, RadiusTemplate, SassTemplate, ScssTemplate, Settings, TemplateError

Constant Summary collapse

VERSION =
'1.0.12'

Class Method Summary collapse

Methods included from Upgrades

upgrade!

Class Method Details

.bootstrap(new_root = nil) ⇒ Object

Bootstrap will set up Frank up at a root path, and read in the setup.rb


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/frank/base.rb', line 222

def self.bootstrap(new_root = nil)
  Frank.reset
  Frank.root = new_root if new_root


  # setup compass
  begin
    require 'compass'

    Compass.configuration do |config|
      # project_path should be the directory to which the sass directory is relative.
      # I think maybe this should be one more directory up from the configuration file.
      # Please update this if it is or remove this message if it can stay the way it is.
      config.project_path = Frank.root
      config.sass_dir = File.join('dynamic', 'stylesheets')
    end

    # sass_engine_options returns a hash, you can merge it with other options.
    Frank.sass_options = Compass.sass_engine_options
  rescue LoadError
    # ignore if compass is not there
  end

  # try to pull in setup
  setup = File.join(Frank.root, 'setup.rb')

  if File.exists?(setup)
    load setup
  elsif File.exist? File.join(Dir.pwd, 'settings.yml')
    puts "\033[31mFrank could not find setup.rb, perhaps you need to upgrade with the `frank upgrade\' command \033[0m"
    exit!
  end

end

.configureObject


43
44
45
46
# File 'lib/frank.rb', line 43

def configure
  settings = Frank::Settings.instance
  block_given? ? yield(settings) : settings
end

.new(&block) ⇒ Object

starts the server


258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/frank/base.rb', line 258

def self.new(&block)
  base = Base.new(&block)

  builder = Rack::Builder.new do
    use Frank::Middleware::Statik, :root => Frank.static_folder
    use Frank::Middleware::Refresh, :watch => [ Frank.dynamic_folder, Frank.static_folder, Frank.layouts_folder ]
    run base
  end

  unless Frank.environment == :test
    message = ['got it under control', 'got your back', 'holdin\' it down', 'takin\' care of business', 'workin\' some magic'].sort_by{rand}.first.strip

    puts "\n-----------------------"
    if Frank.serving_static?
      puts " This doesn't look like a frank project. Frank's serving this folder up his way..."
    else
      puts " Frank's #{ message }..."
    end
    puts " #{Frank.server.hostname}:#{Frank.server.port} \n\n"

    begin
      server = Rack::Handler.get(Frank.server.handler)
    rescue LoadError
      puts "\n\nUnable to find handler for: #{Frank.server.handler}"
      puts "\nUse `gem install #{Frank.server.handler}' to install it"
      puts "\nDefaulting to using webrick"
      server = Rack::Handler.get("webrick")
    end

    server.run(builder, :Port => Frank.server.port, :Host => Frank.server.hostname) do
      trap(:INT) { puts "\n\n-----------------------\n Show's over, fellas.\n\n"; exit }
    end
  end

  base

  rescue Errno::EADDRINUSE
    puts " Hold on a second... Frank works alone.\n \033[31mSomething's already using port #{Frank.server.port}\033[0m\n\n"
end

.stub(project) ⇒ Object

copies over the generic project template


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/frank/base.rb', line 299

def self.stub(project)
  templates_dir = File.join(ENV['HOME'], '.frank_templates')
  choice = nil

  puts "\nFrank is...\n - \033[32mCreating\033[0m your project '#{project}'"

  # if user has a ~/.frank_templates folder
  # provide an interface for choosing template
  if File.exist? templates_dir
    templates = %w[default] + Dir[File.join(templates_dir, '**')].map { |d| d.split('/').last }

    puts "\nWhich template would you like to use? "
    templates.each_with_index { |t, i| puts " #{i + 1}. #{t}" }

    print '> '

    # get input and wait for a valid response
    trap(:INT) { puts "\nbye"; exit }
    choice = STDIN.gets.chomp
    until ( choice.match(/^\d+$/) && templates[choice.to_i - 1] ) || choice == '1'
      print " `#{choice}' \033[31mis not a valid template choice\033[0m\n> "
      choice = STDIN.gets.chomp
    end
  end

  Dir.mkdir project
  template = choice.nil? ? 'default' : templates[choice.to_i - 1]

  puts " - \033[32mCopying\033[0m #{template} Frank template"

  if template == 'default'
    FileUtils.cp_r( Dir.glob(File.join(LIBDIR, 'template/*')), project )
  else
    FileUtils.cp_r( Dir.glob(File.join(templates_dir, "#{template}/*")), project )
  end

  puts "\n \033[32mCongratulations, '#{project}' is ready to go!\033[0m"
rescue Errno::EEXIST
  puts "\n \033[31muh oh, directory '#{project}' already exists...\033[0m"
  exit
end