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/settings.rb,
lib/frank/upgrades.rb,
lib/frank/tilt_setup.rb,
lib/frank/template_helpers.rb,
lib/frank/middleware/imager.rb,
lib/frank/middleware/statik.rb,
lib/frank/middleware/refresh.rb
Overview
relay
Defined Under Namespace
Modules: Middleware, Publish, Render, Rescue, TemplateHelpers, Upgrades Classes: Base, CLI, Compile, ConfigError, Lorem, RadiusTemplate, SassTemplate, ScssTemplate, Settings, TemplateError
Constant Summary collapse
- VERSION =
'1.0.5'
Class Method Summary collapse
-
.bootstrap(new_root = nil) ⇒ Object
Bootstrap will set up Frank up at a root path, and read in the setup.rb.
- .configure ⇒ Object
-
.new(&block) ⇒ Object
starts the server.
-
.stub(project) ⇒ Object
copies over the generic project template.
Methods included from Upgrades
Class Method Details
.bootstrap(new_root = nil) ⇒ Object
Bootstrap will set up Frank up at a root path, and read in the setup.rb
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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/frank/base.rb', line 231 def self.bootstrap(new_root = nil) Frank.reset Frank.root = new_root if new_root if %w[publish p].include? ARGV.first begin require 'net/ssh' require 'net/scp' rescue LoadError puts "\033[31mpublish requires the 'net-scp' gem. `gem install net-scp'\033[0m" exit! end end # 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. = Compass. 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 |
.configure ⇒ Object
42 43 44 45 |
# File 'lib/frank.rb', line 42 def configure settings = Frank::Settings.instance block_given? ? yield(settings) : settings end |
.new(&block) ⇒ Object
starts the server
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/frank/base.rb', line 276 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 = ['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 #{ }..." 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
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/frank/base.rb', line 317 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 |