Sha256: 1b05bb092355d20ffd47b3ed3262a815eddf639d4028cc8a075b236a7a4d27d5

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'rails/generators/migration'
require File.expand_path('../../formats', __FILE__)

module Neutral
  module Generators
    class InstallGenerator < ::Rails::Generators::Base
      include ::Rails::Generators::Migration
      include Neutral::Formats

      source_root File.expand_path("../templates", __FILE__)

      def migrations
        migration_template "votes.rb", "db/migrate/create_neutral_votes"
        migration_template "votings.rb", "db/migrate/create_neutral_votings"
      end

      def routes
        route "neutral"
      end

      def locale
        template "locale.yml", "config/locales/neutral.yml"
      end

      def stylesheet
        if File.binread(css_format[0]).include? "require neutral"
          say_status "skipped", "insert into '#{css_format[0]}'", :yellow
        else
          insert_into_css
        end
      end

      def initializer
        template "initializer.rb", "config/initializers/neutral.rb"
      end

      private
      def insert_into_css
        if File.binread(css_format[0]).include? "require_self"
          insert_into_file css_format[0], "\n#{css_format[1]} require neutral\n", after: /require_self/
        else
          prepend_to_file css_format[0], "/*\n#{css_format[1]} require neutral\n*/\n"
        end
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neutral-0.0.7 lib/generators/neutral/install/install_generator.rb