Sha256: d328611a0a35c7e4ea6fda932bc3024dbe4f0bfefe61063276ececacff796cae
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 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}_controllers.rb") gsub_file, file, /def show\r?\nend/, <<QUOTE respond_to do |format| format.html format.zip { send_file @#{task.classify.uderscore}.zip_path } end QUOTE 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.1 | lib/generators/sibyl/model/model_generator.rb |