Sha256: a4a346b90fe3e3fa4ed370b196e0342060ef805606ec4823d3541c53f86b4beb

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

require 'rails/generators'
require 'rails/generators/migration'

class NativeGenerator < Rails::Generators::Base

    include Rails::Generators::Migration

    source_root File.join File.dirname(__FILE__), 'templates'
    desc 'Install Native'

    def self.next_migration_number dirname
        if ActiveRecord::Base.timestamped_migrations
            Time.now.utc.strftime '%Y%m%d%H%M%S'
        else
            "%.3d" % ( current_migration_number(dirname) + 1 )
        end
    end

    def create_initializer
        template 'initializer.rb', 'config/initializers/native.rb'
    end

    def create_app_model
        migration_template 'apps_migration.rb.erb', 'db/migrate/native_migration.rb', migration_version: migration_version
        template 'app_model.rb', 'app/models/native/app.rb'
    end

    def create_assets
        create_assets_for 'android'
        create_assets_for 'ios'
        create_assets_for 'uwp'
        create_assets_for 'chrome'
        create_assets_for 'osx'
        create_assets_for 'win32'
        create_assets_for 'win64'
        create_assets_for 'lin32'
        create_assets_for 'lin64'
        create_assets_for 'web'
    end

    def show_readme
        readme 'README.md'
    end

    private

    def migration_version
        if Rails.version >= '5.0.0'
            "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
        end
    end

    def create_assets_for platform
        @platform = platform
        template 'application.css.erb', "app/assets/stylesheets/native/#{platform}.css"
        template '.keep', "app/assets/stylesheets/native/#{platform}/.keep"
        template 'application.js.erb', "app/assets/javascripts/native/#{platform}.js"
        template '.keep', "app/assets/javascripts/native/#{platform}/.keep"
    end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
native-2.1.4 lib/generators/native_generator.rb
native-2.1.3 lib/generators/native_generator.rb
native-2.1.2 lib/generators/native_generator.rb
native-2.1.1 lib/generators/native_generator.rb
native-2.1.0 lib/generators/native_generator.rb