Class: MrHyde::Extensions::New

Inherits:
Jekyll::Commands::New
  • Object
show all
Defined in:
lib/mr_hyde/extensions/new.rb

Class Method Summary collapse

Class Method Details

.create_blank_site(path, opts) ⇒ Object



45
46
47
48
49
50
# File 'lib/mr_hyde/extensions/new.rb', line 45

def create_blank_site(path, opts)
  Dir.chdir(path) do
    FileUtils.mkdir(%w(_posts _drafts))
    FileUtils.touch("index.html")
  end
end

.create_independant_sample_files(args, opts) ⇒ Object



58
59
60
# File 'lib/mr_hyde/extensions/new.rb', line 58

def create_independant_sample_files(args, opts)
  Jekyll::Commands::New.process args, opts
end

.create_sample_files(path, opts) ⇒ Object



52
53
54
55
56
# File 'lib/mr_hyde/extensions/new.rb', line 52

def create_sample_files(path, opts)
  FileUtils.cp_r subsite_template + '/.', path
  FileUtils.cp_r subsite_template + '/_posts', path
  FileUtils.rm File.expand_path(scaffold_path, path) 
end

.default_config_fileObject



16
17
18
# File 'lib/mr_hyde/extensions/new.rb', line 16

def default_config_file
  File.join template, '_config.yml'
end

.initialized_post_nameObject



66
67
68
# File 'lib/mr_hyde/extensions/new.rb', line 66

def initialized_post_name
  "_posts/#{Time.now.strftime('%Y-%m-%d')}-welcome-to-mr-hyde.markdown"
end

.process(args, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mr_hyde/extensions/new.rb', line 20

def process(args, options = {})
  raise ArgumentError.new('You must specify a path.') if args.empty?

  new_site_path = File.expand_path(args.join(" "), Dir.pwd)
  FileUtils.mkdir_p new_site_path
  if preserve_source_location?(new_site_path, options)
    Jekyll.logger.abort_with "Conflict:", "#{new_site_path} exists and is not empty."
  end

  if options["blank"]
    create_blank_site new_site_path, options
    Jekyll.logger.info "New jekyll site installed in #{new_site_path}."
  elsif options["full"]
    create_independant_sample_files args, options
  else 
    create_sample_files new_site_path, options

    File.open(File.expand_path(initialized_post_name, new_site_path), "w") do |f|
      f.write(scaffold_post_content)
    end
    Jekyll.logger.info "New jekyll site installed in #{new_site_path}."
  end

end

.scaffold_pathObject



70
71
72
# File 'lib/mr_hyde/extensions/new.rb', line 70

def scaffold_path
  "_posts/0000-00-00-welcome-to-mr-hyde.markdown.erb"
end

.scaffold_post_contentObject



62
63
64
# File 'lib/mr_hyde/extensions/new.rb', line 62

def scaffold_post_content
    ERB.new(File.read(File.expand_path(scaffold_path, subsite_template))).result
end

.subsite_templateObject



8
9
10
# File 'lib/mr_hyde/extensions/new.rb', line 8

def subsite_template
  File.expand_path "../../subsite_template", File.dirname(__FILE__)
end

.templateObject



12
13
14
# File 'lib/mr_hyde/extensions/new.rb', line 12

def template
  site_template
end