def run
if arguments.length != 1
raise Nanoc::Errors::GenericTrivial, "usage: #{command.usage}"
end
identifier = arguments[0].cleaned_identifier
self.require_site
self.set_vcs(options[:vcs])
if !self.site.layouts.find { |l| l.identifier == identifier }.nil?
raise Nanoc::Errors::GenericTrivial,
"A layout already exists at #{identifier}. Please " +
"pick a unique name for the layout you are creating."
end
if identifier == '/'
raise Nanoc::Errors::GenericTrivial,
"There cannot be a layout with the identifier '/'; " +
"please pick a different identifier for this layout."
end
Nanoc::NotificationCenter.on(:file_created) do |file_path|
Nanoc::CLI::Logger.instance.file(:high, :create, file_path)
end
data_source = self.site.data_sources[0]
data_source.create_layout(
"<html>\n" +
" <head>\n" +
" <title><%= @item[:title] %></title>\n" +
" </head>\n" +
" <body>\n" +
" <p>Hi, I'm a new layout. Please customize me!</p>\n" +
"<%= yield %>\n" +
" </body>\n" +
"</html>\n",
{},
identifier
)
puts "A layout has been created at #{identifier}."
end