Sha256: 9e64f7878eb102c1c0f4dc2e5cdf3421aea11818f32811daf97262e1abdd11bd
Contents?: true
Size: 1.49 KB
Versions: 8
Compression:
Stored size: 1.49 KB
Contents
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
Version data entries
8 entries across 8 versions & 1 rubygems