Class: Awestruct::CLI::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/cli/init.rb

Constant Summary

BASE_MANIFEST =
Manifest.new {
  mkdir('_config')
  mkdir('_layouts')
  mkdir('_ext')
  copy_file('_ext/pipeline.rb', Init.framework_path('base_pipeline.rb'))
  copy_file('.awestruct_ignore', Init.framework_path('base_awestruct_ignore'))
  copy_file('Rakefile', Init.framework_path('base_Rakefile'))
  mkdir('stylesheets')
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = Dir.pwd, framework = 'compass', scaffold = true) ⇒ Init

Returns a new instance of Init



22
23
24
25
26
# File 'lib/awestruct/cli/init.rb', line 22

def initialize(dir = Dir.pwd, framework = 'compass', scaffold = true)
  @dir = dir
  @framework = framework
  @scaffold = scaffold
end

Class Method Details

.framework_path(path, framework = nil) ⇒ Object



8
9
10
# File 'lib/awestruct/cli/init.rb', line 8

def self.framework_path(path, framework = nil)
  File.join [File.dirname(__FILE__), '..', 'frameworks', framework, path].compact
end

Instance Method Details

#framework_path(path, framework = nil) ⇒ Object



78
79
80
# File 'lib/awestruct/cli/init.rb', line 78

def framework_path(path, framework = nil)
  Init.framework_path path, framework
end

#runObject



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
# File 'lib/awestruct/cli/init.rb', line 28

def run()
  manifest = Manifest.new(BASE_MANIFEST)
  scaffold_name = @framework
  manifest.template_file('Gemfile', Init.framework_path('base_Gemfile'), {:framework => @framework})

  lib = nil
  case @framework
    when 'bootstrap'
      lib = 'bootstrap-sass'
    when 'foundation'
      lib = 'zurb-foundation'
  end
  unless lib.nil?
    require 'sass/callbacks'
    require 'compass'
    require 'compass/commands'
    require lib
    manifest.install_compass(@framework, lib)
  end
  if (@scaffold)
    manifest.copy_file('_config/site.yml', framework_path('base_site.yml'), :overwrite => true)
    manifest.copy_file('_layouts/base.html.haml', framework_path('base_layout.html.haml', scaffold_name))
    base_index = framework_path('base_index.html.haml', scaffold_name)
    if File.file? base_index
      manifest.copy_file('index.html.haml', base_index)
    else
      manifest.copy_file('index.html.haml', framework_path('base_index.html.haml'))
    end

    humans_txt = framework_path('humans.txt')
    if File.file? humans_txt
      manifest.copy_file('humans.txt', humans_txt, :overwrite => true)
    end

    manifest.touch_file('_config/site.yml')
    manifest.add_requires('_ext/pipeline.rb', [lib]) unless lib.nil?
    if scaffold_name == 'foundation'
      manifest.remove_file('index.html')
      manifest.remove_file('MIT-LICENSE.txt')
    end
  end
  begin
    manifest.perform(@dir)
  rescue => e
    puts e.backtrace
    puts e.message
    puts manifest.steps
  end
end