Sha256: fda4d2828059a0b74be058bbbb69ecc1c5b6074853abdbc39ca536b42fea5131

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

require 'thor/group'
require 'active_support'
require 'active_support/core_ext'

module Locomotive
  module Builder
    module Generators
      class Snippet < 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 snippet localized ?')
            self.locales = ask('What are the locales other than the default one (comma separated) ?').split(',').map(&:strip)
          end
        end

        def create_snippet
          extension = self.haml ? 'liquid.haml' : 'liquid'

          options   = { slug: slug, translated: false }
          file_path = File.join(pages_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 pages_path
          File.join(target_path, 'app', 'views', 'snippets')
        end

      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotivecms_builder-1.0.0.alpha8 lib/locomotive/builder/generators/snippet.rb
locomotivecms_builder-1.0.0.alpha7 lib/locomotive/builder/generators/snippet.rb
locomotivecms_builder-1.0.0.alpha6 lib/locomotive/builder/generators/snippet.rb
locomotivecms_builder-1.0.0.alpha5 lib/locomotive/builder/generators/snippet.rb
locomotivecms_builder-1.0.0.alpha4 lib/locomotive/builder/generators/snippet.rb
locomotivecms_builder-1.0.0.alpha3 lib/locomotive/builder/generators/snippet.rb
locomotivecms_builder-1.0.0.alpha2 lib/locomotive/builder/generators/snippet.rb
locomotivecms_builder-1.0.0.alpha1 lib/locomotive/builder/generators/snippet.rb