Sha256: df4169803f8dab734efdd4a8798b0a217bea4393a58f3982cf24daf6ebf8bf2a
Contents?: true
Size: 1.54 KB
Versions: 39
Compression:
Stored size: 1.54 KB
Contents
require 'thor/group' require 'active_support' require 'active_support/core_ext' module Locomotive module Wagon module Generators class Snippet < Thor::Group include Thor::Actions include Locomotive::Wagon::CLI::ForceColor argument :slug argument :locales argument :target_path # path to the site attr_accessor :haml def ask_for_haml self.haml = yes?('Do you prefer a HAML template ?') end def apply_locales? self.locales.shift # remove the default locale unless self.locales.empty? unless yes?('Do you want to generate files for each locale ?') self.locales = [] end end end def create_snippet extension = self.haml ? 'liquid.haml' : 'liquid' _slug = slug.clone.downcase.gsub(/[-]/, '_') options = { slug: _slug, translated: false } file_path = File.join(snippets_path, _slug) 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 def self.source_root File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'snippet') end protected def snippets_path File.join(target_path, 'app', 'views', 'snippets') end end end end end
Version data entries
39 entries across 39 versions & 1 rubygems