Class: Octopress::Scaffold

Inherits:
Object
  • Object
show all
Defined in:
lib/octopress/scaffold.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, options) ⇒ Scaffold

Returns a new instance of Scaffold.



7
8
9
10
11
# File 'lib/octopress/scaffold.rb', line 7

def initialize(args, options)
  @path  = init_path(args)
  @force = !!options['force']
  @blank = !!options['blank']
end

Instance Attribute Details

#forceObject (readonly)

Returns the value of attribute force.



5
6
7
# File 'lib/octopress/scaffold.rb', line 5

def force
  @force
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/octopress/scaffold.rb', line 5

def path
  @path
end

Instance Method Details

#init_path(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/octopress/scaffold.rb', line 13

def init_path(args)
  path = File.expand_path(args.join(" "), Dir.pwd)
  config_file = File.join(path, '_config.yml') 

  # If there is a Jekyll configuration file present
  # Add template to source directory
  if File.exist?(config_file)
    config = SafeYAML.load_file(config_file)
    if config['source']
      path = File.join(path, config['source'])
    end
  end
  path
end

#local_pathObject



38
39
40
41
# File 'lib/octopress/scaffold.rb', line 38

def local_path
  pwd = File.join(Dir.pwd, '')
  path.sub(pwd, '')
end

#scaffold_file_listObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/octopress/scaffold.rb', line 54

def scaffold_file_list
  scaffold_files.map do |file| 
    name = file.sub(File.join(scaffold_path, ''), '')
    name = name.gsub(/[^\/]+\//, '  ')

    if File.directory?(file)
      name = File.join(name, '')
    end

    " + " + name
  end.join("\n")
end

#scaffold_filesObject

Returns a list of



48
49
50
51
52
# File 'lib/octopress/scaffold.rb', line 48

def scaffold_files
  Find.find(scaffold_path).to_a.reject do |file| 
    file == scaffold_path
  end
end

#scaffold_pathObject



43
44
45
# File 'lib/octopress/scaffold.rb', line 43

def scaffold_path
  Octopress.gem_dir('scaffold')
end

#writeObject



28
29
30
31
32
33
34
35
36
# File 'lib/octopress/scaffold.rb', line 28

def write
  if !@force && File.exist?(File.join(path, '_templates'))
    abort "Some files already exist.  Use --force to overwrite."
  end

  FileUtils.cp_r(File.join(scaffold_path, '.'), path)
  puts "Added Octopress scaffold:"
  puts scaffold_file_list.green
end