Class: Octopress::Scaffold
- Inherits:
-
Object
- Object
- Octopress::Scaffold
- Defined in:
- lib/octopress/scaffold.rb
Instance Attribute Summary collapse
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #init_path(args) ⇒ Object
-
#initialize(args, options) ⇒ Scaffold
constructor
A new instance of Scaffold.
- #local_path ⇒ Object
- #scaffold_file_list ⇒ Object
-
#scaffold_files ⇒ Object
Returns a list of.
- #scaffold_path ⇒ Object
- #write ⇒ Object
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, ) @path = init_path(args) @force = !!['force'] @blank = !!['blank'] end |
Instance Attribute Details
#force ⇒ Object (readonly)
Returns the value of attribute force.
5 6 7 |
# File 'lib/octopress/scaffold.rb', line 5 def force @force end |
#path ⇒ Object (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.(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_path ⇒ Object
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_list ⇒ Object
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_files ⇒ Object
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_path ⇒ Object
43 44 45 |
# File 'lib/octopress/scaffold.rb', line 43 def scaffold_path Octopress.gem_dir('scaffold') end |
#write ⇒ Object
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 |