Sha256: bd649fa7591db31a57327690a0749d7039c800b8ac64dc4712aa5e6e2de98a2c

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'rails/generators/active_record'

module Sibyl
	class ModelGenerator < ActiveRecord::Generators::Base
		desc "Prepare Sibyl model and views"
		argument :task, type: :string

		def inject_into_model
			file = Rails.root.join("app", "models", "#{task.classify.underscore}.rb")
			inject_into_file file, after: "class #{task.classify} < ApplicationRecord" do
				"\n  include Sibyl::Task\n"
			end
		end

		def modify_controller
			file = Rails.root.join("app", "controllers", "#{task}_controller.rb")
			gsub_file file, /def show *(\r?\n)\s*end/, "def show\n    respond_to do |format|\n      format.html\n      format.zip  { send_file @#{task.classify.underscore}.zip_path }\n    end\n  end"
		end

		def modify_view
			file = Rails.root.join("app", "views", task, "index.html.erb")
			gsub_file file, "<th colspan=\"3\"></th>", "<th colspan=\"4\"></th>"
			inject_into_file file, after: "<td><%= link_to 'Show', #{task.classify.underscore} %></td>" do
				"\n      <td><%= link_to 'Download', #{task.classify.underscore}_path(#{task.classify.underscore})+'.zip' %></td>"
			end
		end

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sibyl-0.2.0 lib/generators/sibyl/model/model_generator.rb