Sha256: 764c6276dff46d9ea13e048325dca3902b8541e86748ab1535ba9407d7742942

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Susanoo
  module Generators
    class NgModule < Thor::Group
      include Thor::Actions

      desc 'Create an AngularJS module.'

      argument :name, type: :string, desc: 'Name of AngularJS'
      class_option :deps, type: :string, default: '', desc: 'Dependencies of Angularjs module, comma separated'

      def self.source_root
        File.join(File.dirname(__FILE__),
                  '../templates/generators/ng_module')
      end

      def self.global_generator?
        false
      end

      def setup_directories
        empty_directory "src/views/#{directory_name}#{module_name}"

        mpath = 'src/assets/javascripts/modules/'
        empty_directory "#{mpath}#{directory_name}" unless directory_name.nil?
      end

      def install_js_module
        template 'module.js.erb', "src/assets/javascripts/modules/#{directory_name}#{module_name}.js"
      end

      def install_view
        template('index.html.erb',
                 "src/views/#{directory_name}#{module_name}/index.html")
      end

      private

      def directory_name
        dir_name = name.split('/')[0..-2].join('/')
        return dir_name + '/' unless dir_name.empty?
        nil
      end

      def module_name
        name.split('/')[-1].underscore
      end

      def dependencies
        options[:deps].split(',')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
susanoo-0.8.0 lib/susanoo/generators/ng_module.rb