implemented the command to generate a page

did committed Jan 16, 2013
commit 6696151981eecd824519a6ff42454b935d608af4
Showing 5 changed files with 111 additions and 4 deletions
TODO +1 -1
@@ @@ -31,7 +31,7 @@ x params to launch the thin server (port, address ?)
x content types
x definitions
x data (Faker)
- - page
+ x page
- snippet
- push:
- option to select to push only some parts (pages, ...etc)
generators/page/template.liquid.haml.tt +35 -0
@@ @@ -0,0 +1,35 @@
+ ---
+ title: <%= config[:slug].humanize -%>
+ <% if config[:translated] %>
+
+ # TODO: explain it (used only if the page is not for the defaut locale)
+ slug: <%= config[:slug] -%>
+ <% end %>
+
+ # TODO: explain it
+ listed: true
+
+ # TODO: explain it
+ published: true
+
+ # TODO: explain it
+ # position: 1
+
+ # TODO: explain it
+ # redirect_url: "<url to a page or to a remote url>"
+
+ # TODO: explain it
+ # content_type: "<slug of one of the content types>"
+
+ # TODO: explain it
+ # editable_elements:
+ # 'some_block/some_slug': "<text>"
+ # 'some_block/some_slug': "<relative path to the file under the public/samples folder>"
+ ---
+ {% extends parent %}
+
+ {% block main %}
+
+ %p Hello world
+
+ {% endblock %}
\ No newline at end of file
generators/page/template.liquid.tt +1 -0
@@ @@ -0,0 +1 @@
+ TEST LIQUID
\ No newline at end of file
locomotive/builder/cli.rb b/lib/locomotive/builder/cli.rb +17 -3
@@ @@ -32,9 +32,23 @@ module Locomotive
end
end
- desc 'page PATH', 'Create a page whose NAME is its fullpath'
- def page(path)
- puts "TODO [page] #{path}"
+ desc 'page FULLPATH', 'Create a page. No need to pass an extension to the FULLPATH arg'
+ long_desc <<-LONGDESC
+ Create a page. The generator will ask for the extension (liquid or haml) and also
+ if the page is localized or not.
+
+ Examples:
+
+ * builder generate page contact
+
+ * builder generate page about_us/me
+ LONGDESC
+ def page(fullpath)
+ if path = check_path!
+ Locomotive::Builder.generate :page, fullpath, self.options['path']
+ else
+ say 'The path does not point to a LocomotiveCMS site', :red
+ end
end
desc 'snippet NAME', 'Create a snippet'
locomotive/builder/generators/page.rb b/lib/locomotive/builder/generators/page.rb +57 -0
@@ @@ -0,0 +1,57 @@
+ require 'thor/group'
+ require 'active_support'
+ require 'active_support/core_ext'
+
+ module Locomotive
+ module Builder
+ module Generators
+ class Page < Thor::Group
+
+ include Thor::Actions
+
+ argument :slug
+ argument :target_path # path to the site
+
+ attr_accessor :haml, :locales
+
+ def ask_for_haml_and_locales
+ self.locales = []
+ self.haml = yes?('Do you prefer a HAML template ?')
+
+ if yes?('Is your page localized ?')
+ self.locales = ask('What are the locales other than the default one (comma separated) ?').split(',').map(&:strip)
+ end
+ end
+
+ def create_page
+ extension = self.haml ? 'liquid.haml' : 'liquid'
+
+ segments = self.slug.split('/')
+ while segment = segments.pop do
+ options = { slug: segment, translated: false }
+ file_path = File.join(pages_path, segments, segment)
+
+ template "template.#{extension}.tt", "#{file_path}.#{extension}", options
+
+ self.locales.each do |locale|
+ options[:translated] = true
+ template "template.#{extension}.tt", "#{file_path}.#{locale}.#{extension}", options
+ end
+ end
+ end
+
+ def self.source_root
+ File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'page')
+ end
+
+ protected
+
+ def pages_path
+ File.join(target_path, 'app', 'views', 'pages')
+ end
+
+ end
+
+ end
+ end
+ end
\ No newline at end of file