Sha256: dd702ee971dfd33ae10c4a6def85dfe60005ce4899c1e256ec03672b8d1d9918

Contents?: true

Size: 1.38 KB

Versions: 63

Compression:

Stored size: 1.38 KB

Contents

require 'rails/generators/active_record'

module BootswatchRails
  module Generators
    class CleditorGenerator < ActiveRecord::Generators::Base
      desc "Turn text_area(s) into rich edit fields with CLEditor"
      argument :name, type: :string,
               desc: "The resource with textareas to be enhanced"
      argument :columns, type: :array, banner: "COLUMN [...]",
               desc: "The names of the textarea columns"
      source_root File.expand_path('../templates', __FILE__)
      
      def add_to_assets
        file = "app/assets/javascripts/application.js"
        inject_into_file file, "\n//= require jquery.cleditor", after: /require jquery_ujs$/
        file = "app/assets/stylesheets/application.css"
        inject_into_file file, " *= require jquery.cleditor\n", before: /^.*require_self/
      end
      
      def add_to_view
        file = "app/views/#{table_name}/index.html.erb"
        columns.each do |column|
          gsub_file file, / (#{name}\.#{column}) /, " raw(\\1) "
        end
        file = "app/views/#{table_name}/show.html.erb"
        columns.each do |column|
          gsub_file file, / (@#{name}\.#{column}) /, " raw(\\1) "
        end
        file = "app/views/#{table_name}/_form.html.erb"
        columns.each do |column|
          gsub_file file, / (:#{column}) /, " \\1, input_html: { class: 'cleditor' } "
        end
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
bootswatch_rails-3.3.7.8 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.7 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.6 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.5 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.4 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.3 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.2 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.1 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.7.0 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.6.2 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.6.1 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.5.2 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.5.1 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.4.1 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.2.1 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.1.2 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.1.1 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.1.0 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.0.11 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb
bootswatch_rails-3.3.0.10 lib/generators/bootswatch_rails/cleditor/cleditor_generator.rb