Class: Usmu::Plugin::Core
- Inherits:
-
Object
- Object
- Usmu::Plugin::Core
- Defined in:
- lib/usmu/plugin/core.rb
Overview
Usmu Core's plugin. We dog-food several plugin integration points.
Instance Method Summary collapse
-
#command_generate(args, options) ⇒ void
Command to generate a website.
-
#command_init(args, options) ⇒ void
Command to initialise a new website.
-
#commands(ui, c) ⇒ void
We add two commands:
generateandinit [path]. -
#init_copy_file(from, to, file) ⇒ void
private
Helper to copy a file.
-
#initialize ⇒ Core
constructor
Basic constructor.
Constructor Details
#initialize ⇒ Core
Basic constructor.
8 9 10 |
# File 'lib/usmu/plugin/core.rb', line 8 def initialize @log = Logging.logger[self] end |
Instance Method Details
#command_generate(args, options) ⇒ void
Command to generate a website.
37 38 39 40 |
# File 'lib/usmu/plugin/core.rb', line 37 def command_generate(args, ) @site_generator = Usmu::SiteGenerator.new(@ui.configuration) @site_generator.generate end |
#command_init(args, options) ⇒ void
Command to initialise a new website.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/usmu/plugin/core.rb', line 46 def command_init(args, ) @log.info("Usmu v#{Usmu::VERSION}") @log.info('') if args.length > 1 @log.fatal('Only one path allowed to be initialised at a time.') raise end path = args.length == 1 ? args.shift : '.' from = File.realpath(File.join(File.dirname(__FILE__), '../../../share/init-site')) @log.info("Copying #{from} -> #{path}") Dir["#{from}/**/{*,.??*}"].each {|f| init_copy_file(from, path, f) } end |
#commands(ui, c) ⇒ void
We add two commands: generate and init [path].
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/usmu/plugin/core.rb', line 17 def commands(ui, c) @log.debug('Adding core console commands...') @ui = ui c.command(:generate) do |command| command.syntax = 'usmu generate' command.description = 'Generates your website using the configuration specified.' command.action &method(:command_generate) end c.command(:init) do |command| command.syntax = 'usmu init [path]' command.description = 'Initialise a new website in the given path, or the current directory if none given.' command.action &method(:command_init) end end |
#init_copy_file(from, to, file) ⇒ void (private)
Helper to copy a file.
69 70 71 72 73 74 75 76 77 |
# File 'lib/usmu/plugin/core.rb', line 69 def init_copy_file(from, to, file) output_name = file[(from.length + 1)..file.length] @log.success "Creating #{output_name}..." unless File.directory? file output_path = "#{to}/#{output_name}" FileUtils.mkdir_p File.dirname(output_path) unless File.directory? File.dirname(output_path) FileUtils.copy(file, output_path) end end |