Class: MrHyde::Extensions::New
- Inherits:
-
Jekyll::Commands::New
- Object
- Jekyll::Commands::New
- MrHyde::Extensions::New
- Defined in:
- lib/mr_hyde/extensions/new.rb
Class Method Summary collapse
- .create_blank_site(path, opts) ⇒ Object
- .create_independant_sample_files(args, opts) ⇒ Object
- .create_sample_files(path, opts) ⇒ Object
- .default_config_file ⇒ Object
- .initialized_post_name ⇒ Object
- .process(args, options = {}) ⇒ Object
- .scaffold_path ⇒ Object
- .scaffold_post_content ⇒ Object
- .subsite_template ⇒ Object
- .template ⇒ Object
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.(scaffold_path, path) end |
.default_config_file ⇒ Object
16 17 18 |
# File 'lib/mr_hyde/extensions/new.rb', line 16 def default_config_file File.join template, '_config.yml' end |
.initialized_post_name ⇒ Object
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
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, = {}) raise ArgumentError.new('You must specify a path.') if args.empty? new_site_path = File.(args.join(" "), Dir.pwd) FileUtils.mkdir_p new_site_path if preserve_source_location?(new_site_path, ) Jekyll.logger.abort_with "Conflict:", "#{new_site_path} exists and is not empty." end if ["blank"] create_blank_site new_site_path, Jekyll.logger.info "New jekyll site installed in #{new_site_path}." elsif ["full"] create_independant_sample_files args, else create_sample_files new_site_path, File.open(File.(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_path ⇒ Object
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_content ⇒ Object
62 63 64 |
# File 'lib/mr_hyde/extensions/new.rb', line 62 def scaffold_post_content ERB.new(File.read(File.(scaffold_path, subsite_template))).result end |
.subsite_template ⇒ Object
8 9 10 |
# File 'lib/mr_hyde/extensions/new.rb', line 8 def subsite_template File. "../../subsite_template", File.dirname(__FILE__) end |
.template ⇒ Object
12 13 14 |
# File 'lib/mr_hyde/extensions/new.rb', line 12 def template site_template end |