require 'pathname' require 'fileutils' require 'tempfile' require 'generators/utils' include FileUtils module Venomi module RailsAdmin if defined? ::Rails @rails_root = Rails.root.to_s @rails_admin_root = "#{@rails_root}/config/initializers/rails_admin.rb" else # Debug @gem_root = Pathname.new File.expand_path('../../', __FILE__).to_s @rails_admin_root = "#{@gem_root}/debug/initializers/rails_admin.rb" end class << self include Venomi::Generators::Utils::InstanceMethods def configure if file?(@rails_admin_root) unless file_include?(@rails_admin_root, "config.model Translation do") replace(@rails_admin_root, "RailsAdmin.config do |config|", ("RailsAdmin.config do |config|\n" + @translation)) end unless file_include?(@rails_admin_root, " new do") replace(@rails_admin_root, " new", @new) end unless file_include?(@rails_admin_root, " delete do") replace(@rails_admin_root, " delete", @delete) end end end def rollback if file? @rails_admin_root text = File.read(@rails_admin_root) text.gsub!(@delete, " delete\n") text.gsub!(@new, " new\n") text.gsub!(@translation, "") File.open(@rails_admin_root, "w") {|file| file.puts text } end end end @new = <<-MSG new do except [:Translation] end MSG @delete = <<-MSG delete do except [:Translation] end MSG @translation = <<-MSG config.model Translation do list do field :key field :value end edit do field :key do read_only true end field :value end end MSG end end