Sha256: 8ecc3913d46e9b4ea06e89abf28cdae2fbe9d02bdcb627137c1c837f3ddeed7b

Contents?: true

Size: 1.73 KB

Versions: 10

Compression:

Stored size: 1.73 KB

Contents

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

      desc 'Create an AngularJS directive.'

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

      class_option :restrict, type: :string, default: 'E',
         desc: 'AngularJS directive restriction types'

      class_option :replace, type: :boolean, default: true,
         desc: 'AngularJS directive replace option'

      # TODO: Add an append class option to allow user
      #       to append the directive to already defined
      #       modules

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

      def self.global_generator?
        false
      end

      def setup_directories
        empty_directory "src/views/directives/#{directive_name}"

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

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

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

      private

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

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
susanoo-0.14.0 lib/susanoo/generators/ng_directive.rb
susanoo-0.13.2 lib/susanoo/generators/ng_directive.rb
susanoo-0.13.1 lib/susanoo/generators/ng_directive.rb
susanoo-0.13.0 lib/susanoo/generators/ng_directive.rb
susanoo-0.12.3 lib/susanoo/generators/ng_directive.rb
susanoo-0.12.2 lib/susanoo/generators/ng_directive.rb
susanoo-0.12.1 lib/susanoo/generators/ng_directive.rb
susanoo-0.12.0 lib/susanoo/generators/ng_directive.rb
susanoo-0.11.1 lib/susanoo/generators/ng_directive.rb
susanoo-0.10.0 lib/susanoo/generators/ng_directive.rb