├── spec ├── dummy │ ├── log │ │ └── .gitkeep │ ├── app │ │ ├── mailers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── page.rb │ │ │ └── admin_user.rb │ │ ├── assets │ │ │ ├── javascripts │ │ │ │ ├── active_admin.js │ │ │ │ └── application.js │ │ │ └── stylesheets │ │ │ │ ├── active_admin.css.scss │ │ │ │ └── application.css │ │ ├── helpers │ │ │ └── application_helper.rb │ │ ├── controllers │ │ │ └── application_controller.rb │ │ ├── admin │ │ │ ├── pages.rb │ │ │ └── dashboard.rb │ │ └── views │ │ │ └── layouts │ │ │ └── application.html.erb │ ├── lib │ │ └── assets │ │ │ └── .gitkeep │ ├── public │ │ ├── favicon.ico │ │ ├── 500.html │ │ ├── 422.html │ │ └── 404.html │ ├── config.ru │ ├── config │ │ ├── environment.rb │ │ ├── routes.rb │ │ ├── locales │ │ │ ├── en.yml │ │ │ └── devise.en.yml │ │ ├── initializers │ │ │ ├── mime_types.rb │ │ │ ├── konacha.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── session_store.rb │ │ │ ├── secret_token.rb │ │ │ ├── wrap_parameters.rb │ │ │ ├── inflections.rb │ │ │ ├── active_admin.rb │ │ │ └── devise.rb │ │ ├── boot.rb │ │ ├── database.yml │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── test.rb │ │ │ └── production.rb │ │ └── application.rb │ ├── db │ │ ├── migrate │ │ │ ├── 20121224200305_create_pages.rb │ │ │ ├── 20121224120152_create_admin_notes.rb │ │ │ ├── 20121224120153_move_admin_notes_to_comments.rb │ │ │ └── 20121224200148_devise_create_admin_users.rb │ │ └── schema.rb │ ├── Rakefile │ ├── script │ │ └── rails │ └── README.rdoc ├── javascripts │ ├── support │ │ └── mock_wysihtml5.js │ ├── spec_helper.js │ ├── templates │ │ └── editor.jst.ejs │ └── editor_spec.js ├── factories.rb ├── support │ └── sign_in_helpers.rb ├── requests │ └── editor_request_spec.rb ├── spec_helper.rb └── lib │ ├── config_spec.rb │ └── policy_spec.rb ├── lib ├── active_admin_editor.rb ├── active_admin │ ├── editor │ │ ├── version.rb │ │ ├── engine.rb │ │ ├── config.rb │ │ ├── policy.rb │ │ └── parser_rules.rb │ └── editor.rb └── generators │ └── active_admin │ └── editor │ ├── templates │ └── active_admin_editor.rb │ └── editor_generator.rb ├── .gitignore ├── app ├── assets │ ├── images │ │ └── active_admin │ │ │ └── editor │ │ │ └── loader.gif │ ├── javascripts │ │ └── active_admin │ │ │ ├── editor │ │ │ ├── templates │ │ │ │ ├── uploader.jst.ejs │ │ │ │ └── toolbar.jst.ejs │ │ │ ├── config.js.erb │ │ │ └── editor.js │ │ │ └── editor.js │ └── stylesheets │ │ └── active_admin │ │ ├── editor.css.scss │ │ └── editor │ │ └── wysiwyg.css └── inputs │ └── html_editor_input.rb ├── .travis.yml ├── Rakefile ├── Gemfile ├── MIT-LICENSE ├── active_admin_editor.gemspec ├── README.md └── Gemfile.lock /spec/dummy/log/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/app/mailers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/lib/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/dummy/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/active_admin_editor.rb: -------------------------------------------------------------------------------- 1 | require 'active_admin/editor' 2 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/active_admin.js: -------------------------------------------------------------------------------- 1 | //= require active_admin/base 2 | -------------------------------------------------------------------------------- /spec/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/javascripts/support/mock_wysihtml5.js: -------------------------------------------------------------------------------- 1 | wysihtml5 = { 2 | Editor: sinon.stub() 3 | } 4 | -------------------------------------------------------------------------------- /spec/dummy/app/models/page.rb: -------------------------------------------------------------------------------- 1 | class Page < ActiveRecord::Base 2 | attr_accessible :content, :title 3 | end 4 | -------------------------------------------------------------------------------- /lib/active_admin/editor/version.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Editor 3 | VERSION = '1.1.0' 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | spec/dummy/db/*.sqlite3 5 | spec/dummy/log/*.log 6 | spec/dummy/tmp/ 7 | spec/dummy/.sass-cache 8 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | end 4 | -------------------------------------------------------------------------------- /app/assets/images/active_admin/editor/loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstacruz/active_admin_editor/master/app/assets/images/active_admin/editor/loader.gif -------------------------------------------------------------------------------- /spec/javascripts/spec_helper.js: -------------------------------------------------------------------------------- 1 | //= require jquery 2 | //= require chai-jquery 3 | //= require sinon 4 | //= require sinon-chai 5 | //= require_tree ./templates 6 | -------------------------------------------------------------------------------- /spec/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Dummy::Application 5 | -------------------------------------------------------------------------------- /spec/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /spec/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | ActiveAdmin.routes(self) 3 | 4 | devise_for :admin_users, ActiveAdmin::Devise.config 5 | 6 | root to: 'admin::pages#index' 7 | end 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.9.2 4 | - 1.9.3 5 | script: bundle exec rake app:db:create:all app:db:migrate spec konacha:run 6 | before_script: 7 | - export DISPLAY=:99.0 8 | - sh -e /etc/init.d/xvfb start 9 | -------------------------------------------------------------------------------- /app/assets/javascripts/active_admin/editor/templates/uploader.jst.ejs: -------------------------------------------------------------------------------- 1 |
2 | or 3 | 4 | 5 |
6 |
7 | -------------------------------------------------------------------------------- /spec/dummy/app/admin/pages.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.register Page do 2 | form do |f| 3 | f.inputs do 4 | f.input :title 5 | f.input :content, as: :html_editor 6 | end 7 | 8 | f.actions 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/active_admin.css.scss: -------------------------------------------------------------------------------- 1 | // Active Admin CSS Styles 2 | @import "active_admin/mixins"; 3 | @import "active_admin/base"; 4 | 5 | // To customize the Active Admin interfaces, add your 6 | // styles here: 7 | -------------------------------------------------------------------------------- /lib/generators/active_admin/editor/templates/active_admin_editor.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin::Editor.configure do |config| 2 | # config.s3_bucket = '' 3 | # config.aws_access_key_id = '' 4 | # config.aws_access_secret = '' 5 | # config.storage_dir = 'uploads' 6 | end 7 | -------------------------------------------------------------------------------- /spec/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /lib/active_admin/editor.rb: -------------------------------------------------------------------------------- 1 | require 'activeadmin' 2 | 3 | require 'active_admin/editor/version' 4 | require 'active_admin/editor/parser_rules' 5 | require 'active_admin/editor/config' 6 | require 'active_admin/editor/policy' 7 | require 'active_admin/editor/engine' 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20121224200305_create_pages.rb: -------------------------------------------------------------------------------- 1 | class CreatePages < ActiveRecord::Migration 2 | def change 3 | create_table :pages do |t| 4 | t.string :title 5 | t.text :content 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /spec/factories.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | sequence :email do |n| 3 | "email#{n}@factory.com" 4 | end 5 | 6 | factory :admin_user do 7 | email 8 | password { 'password' } 9 | password_confirmation { 'password' } 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/assets/javascripts/active_admin/editor.js: -------------------------------------------------------------------------------- 1 | //= require wysihtml5 2 | //= require active_admin/editor/config 3 | //= require active_admin/editor/editor 4 | 5 | ;(function(window, $) { 6 | $(function() { $('.html_editor').editor(window.AA.editor_config) }) 7 | })(window, jQuery) 8 | -------------------------------------------------------------------------------- /spec/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | gemfile = File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | if File.exist?(gemfile) 5 | ENV['BUNDLE_GEMFILE'] = gemfile 6 | require 'bundler' 7 | Bundler.setup 8 | end 9 | 10 | $:.unshift File.expand_path('../../../../lib', __FILE__) -------------------------------------------------------------------------------- /spec/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Dummy::Application.load_tasks 8 | -------------------------------------------------------------------------------- /spec/dummy/script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag "application", :media => "all" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/support/sign_in_helpers.rb: -------------------------------------------------------------------------------- 1 | module SignInHelpers 2 | def sign_in(user) 3 | visit new_admin_user_session_path 4 | fill_in 'Email', :with => user.email 5 | fill_in 'Password', :with => user.password 6 | click_on 'Login' 7 | end 8 | end 9 | 10 | RSpec.configure do |config| 11 | config.include SignInHelpers, :type => :request 12 | end 13 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/konacha.rb: -------------------------------------------------------------------------------- 1 | Konacha.configure do |config| 2 | require 'capybara/poltergeist' 3 | config.driver = :poltergeist 4 | 5 | def Konacha.spec_root 6 | File.expand_path('../../../../../spec/javascripts', __FILE__) 7 | end 8 | 9 | Rails.application.config.assets.paths << Konacha.spec_root 10 | end if defined?(Konacha) 11 | -------------------------------------------------------------------------------- /spec/javascripts/templates/editor.jst.ejs: -------------------------------------------------------------------------------- 1 |
  • 2 | 3 |
    4 | 5 |
    6 |
    7 |
  • 8 | -------------------------------------------------------------------------------- /spec/requests/editor_request_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Editor', :js => true do 4 | before do 5 | sign_in create(:admin_user) 6 | visit new_admin_page_path 7 | end 8 | 9 | it 'adds the input as an html_editor input' do 10 | expect(page).to have_selector('li.html_editor') 11 | end 12 | 13 | it 'intitalizes the editor' do 14 | expect(page).to have_selector('li.html_editor .toolbar') 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/generators/active_admin/editor/editor_generator.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Generators 3 | class EditorGenerator < Rails::Generators::Base 4 | desc 'Installs the active admin html5 editor.' 5 | 6 | source_root File.expand_path('../templates', __FILE__) 7 | 8 | def copy_initializer 9 | template 'active_admin_editor.rb', 'config/initializers/active_admin_editor.rb' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # Dummy::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /spec/dummy/app/models/admin_user.rb: -------------------------------------------------------------------------------- 1 | class AdminUser < ActiveRecord::Base 2 | # Include default devise modules. Others available are: 3 | # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable 4 | devise :database_authenticatable, 5 | :recoverable, :rememberable, :trackable, :validatable 6 | 7 | # Setup accessible (or protected) attributes for your model 8 | attr_accessible :email, :password, :password_confirmation, :remember_me 9 | # attr_accessible :title, :body 10 | end 11 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | Dummy::Application.config.secret_token = '7eb151084ac9c928baf810ee400751d4ac9fc7807ab6fe4108595ee7ddcc8d279624918d38d185b9a7b195c815ccacc9d619605f97e7b6460d0d69bd9e816028' 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # Disable root element in JSON by default. 12 | ActiveSupport.on_load(:active_record) do 13 | self.include_root_in_json = false 14 | end 15 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20121224120152_create_admin_notes.rb: -------------------------------------------------------------------------------- 1 | class CreateAdminNotes < ActiveRecord::Migration 2 | def self.up 3 | create_table :admin_notes do |t| 4 | t.string :resource_id, :null => false 5 | t.string :resource_type, :null => false 6 | t.references :admin_user, :polymorphic => true 7 | t.text :body 8 | t.timestamps 9 | end 10 | add_index :admin_notes, [:resource_type, :resource_id] 11 | add_index :admin_notes, [:admin_user_type, :admin_user_id] 12 | end 13 | 14 | def self.down 15 | drop_table :admin_notes 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | # 12 | # These inflection rules are supported but not enabled by default: 13 | # ActiveSupport::Inflector.inflections do |inflect| 14 | # inflect.acronym 'RESTful' 15 | # end 16 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | -------------------------------------------------------------------------------- /app/inputs/html_editor_input.rb: -------------------------------------------------------------------------------- 1 | class HtmlEditorInput < Formtastic::Inputs::TextInput 2 | def upload_enabled? 3 | ActiveAdmin::Editor.configuration.s3_configured? 4 | end 5 | 6 | def policy 7 | ActiveAdmin::Editor::Policy.new 8 | end 9 | 10 | def wrapper_html_options 11 | return super unless upload_enabled? 12 | super.merge( :data => { :policy => policy.to_json }) 13 | end 14 | 15 | def to_html 16 | html = '
    ' 17 | html << builder.text_area(method, input_html_options) 18 | html << '
    ' 19 | html << '
    ' 20 | input_wrapping do 21 | label_html << html.html_safe 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /spec/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require_tree . 16 | -------------------------------------------------------------------------------- /app/assets/javascripts/active_admin/editor/config.js.erb: -------------------------------------------------------------------------------- 1 | ;(function(window) { 2 | window.AA = (window.AA || {}) 3 | var config = window.AA.editor_config = (window.AA.editor_config || {}) 4 | 5 | <% %w(aws_access_key_id s3_bucket storage_dir).each do |option| %> 6 | config.<%= option %> = '<%= ActiveAdmin::Editor.configuration.send(option.to_sym) %>' 7 | <% end %> 8 | 9 | config.stylesheets = <%= ActiveAdmin::Editor.configuration.stylesheets.map { |stylesheet| asset_path stylesheet }.to_json %> 10 | config.spinner = '<%= asset_path 'active_admin/editor/loader.gif' %>' 11 | config.uploads_enabled = <%= ActiveAdmin::Editor.configuration.s3_configured? %> 12 | config.parserRules = <%= ActiveAdmin::Editor.configuration.parser_rules.to_json %> 13 | })(window) 14 | -------------------------------------------------------------------------------- /spec/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    We're sorry, but something went wrong.

    23 |
    24 | 25 | 26 | -------------------------------------------------------------------------------- /spec/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    The change you wanted was rejected.

    23 |

    Maybe you tried to change something you didn't have access to.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /spec/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
    22 |

    The page you were looking for doesn't exist.

    23 |

    You may have mistyped the address or the page may have moved.

    24 |
    25 | 26 | 27 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | begin 3 | require 'bundler/setup' 4 | rescue LoadError 5 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 6 | end 7 | begin 8 | require 'rdoc/task' 9 | rescue LoadError 10 | require 'rdoc/rdoc' 11 | require 'rake/rdoctask' 12 | RDoc::Task = Rake::RDocTask 13 | end 14 | 15 | Bundler::GemHelper.install_tasks 16 | 17 | APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__) 18 | load 'rails/tasks/engine.rake' 19 | 20 | Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f } 21 | require 'rspec/core' 22 | require 'rspec/core/rake_task' 23 | 24 | desc 'Run all specs in spec directory (excluding plugin specs)' 25 | RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare') 26 | 27 | task :default => :spec 28 | task 'konacha:serve' => 'app:konacha:serve' 29 | task 'konacha:run' => 'app:konacha:run' 30 | -------------------------------------------------------------------------------- /lib/active_admin/editor/engine.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Editor 3 | class Engine < ::Rails::Engine 4 | engine_name 'active_admin_editor' 5 | 6 | ActiveAdmin.application.class_eval do 7 | def editor; ActiveAdmin::Editor.configuration end 8 | end 9 | 10 | initializer 'active_admin.editor', :group => :all do |app| 11 | app.config.assets.precompile += [ 12 | 'active_admin/editor.js', 13 | 'active_admin/editor.css' 14 | ] + ActiveAdmin::Editor.configuration.stylesheets 15 | 16 | ActiveAdmin.application.tap do |config| 17 | config.register_javascript 'active_admin/editor.js' 18 | config.register_stylesheet 'active_admin/editor.css' 19 | 20 | ActiveAdmin::Editor.configuration.stylesheets.each do |stylesheet| 21 | config.register_stylesheet stylesheet 22 | end 23 | end 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | 3 | # Declare your gem's dependencies in active_admin_editor.gemspec. 4 | # Bundler will treat runtime dependencies like base dependencies, and 5 | # development dependencies will be added by default to the :development group. 6 | gemspec 7 | 8 | gem 'meta_search' 9 | gem 'sass-rails' 10 | gem 'coffee-rails' 11 | gem 'uglifier' 12 | gem 'activeadmin' 13 | gem 'konacha' 14 | 15 | # jquery-rails is used by the dummy application 16 | gem 'jquery-rails' 17 | gem 'chai-jquery-rails' 18 | gem 'sinon-chai-rails' 19 | gem 'sinon-rails' 20 | gem 'ejs' 21 | 22 | group :development, :test do 23 | end 24 | 25 | # Declare any dependencies that are still in development here instead of in 26 | # your gemspec. These might include edge Rails or gems from your path or 27 | # Git. Remember to move these dependencies to your gemspec before releasing 28 | # your gem to rubygems.org. 29 | 30 | # To use debugger 31 | # gem 'ruby-debug19', :require => 'ruby-debug' 32 | -------------------------------------------------------------------------------- /spec/dummy/app/admin/dashboard.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.register_page 'Dashboard' do 2 | 3 | menu priority: 1, label: proc { I18n.t('active_admin.dashboard') } 4 | 5 | content title: proc { I18n.t('active_admin.dashboard') } do 6 | div class: 'blank_slate_container', id: 'dashboard_default_message' do 7 | span class: 'blank_slate' do 8 | span I18n.t('active_admin.dashboard_welcome.welcome') 9 | small I18n.t('active_admin.dashboard_welcome.call_to_action') 10 | end 11 | end 12 | 13 | # Here is an example of a simple dashboard with columns and panels. 14 | # 15 | # columns do 16 | # column do 17 | # panel "Recent Posts" do 18 | # ul do 19 | # Post.recent(5).map do |post| 20 | # li link_to(post.title, admin_post_path(post)) 21 | # end 22 | # end 23 | # end 24 | # end 25 | 26 | # column do 27 | # panel "Info" do 28 | # para "Welcome to ActiveAdmin." 29 | # end 30 | # end 31 | # end 32 | end # content 33 | end 34 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2012 YOURNAME 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../dummy/config/environment.rb', __FILE__) 3 | require 'rspec/rails' 4 | require 'rspec/autorun' 5 | require 'factory_girl_rails' 6 | require 'faker' 7 | require 'database_cleaner' 8 | 9 | Rails.backtrace_cleaner.remove_silencers! 10 | 11 | # Load support files 12 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 13 | 14 | RSpec.configure do |config| 15 | config.mock_with :rspec 16 | config.use_transactional_fixtures = false 17 | config.infer_base_class_for_anonymous_controllers = false 18 | config.order = 'random' 19 | 20 | # Database Cleaner 21 | config.before(:suite) do 22 | DatabaseCleaner.clean_with(:truncation) 23 | end 24 | 25 | config.before(:each) do 26 | DatabaseCleaner.strategy = :transaction 27 | end 28 | 29 | config.before(:each, js: true) do 30 | DatabaseCleaner.strategy = :truncation 31 | end 32 | 33 | config.before(:each) do 34 | DatabaseCleaner.start 35 | end 36 | 37 | config.after(:each) do 38 | DatabaseCleaner.clean 39 | end 40 | 41 | # Factory girl helpers 42 | config.include FactoryGirl::Syntax::Methods 43 | end 44 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20121224120153_move_admin_notes_to_comments.rb: -------------------------------------------------------------------------------- 1 | class MoveAdminNotesToComments < ActiveRecord::Migration 2 | def self.up 3 | remove_index :admin_notes, [:admin_user_type, :admin_user_id] 4 | rename_table :admin_notes, :active_admin_comments 5 | rename_column :active_admin_comments, :admin_user_type, :author_type 6 | rename_column :active_admin_comments, :admin_user_id, :author_id 7 | add_column :active_admin_comments, :namespace, :string 8 | add_index :active_admin_comments, [:namespace] 9 | add_index :active_admin_comments, [:author_type, :author_id] 10 | 11 | # Update all the existing comments to the default namespace 12 | say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace." 13 | execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'" 14 | end 15 | 16 | def self.down 17 | remove_index :active_admin_comments, :column => [:author_type, :author_id] 18 | remove_index :active_admin_comments, :column => [:namespace] 19 | remove_column :active_admin_comments, :namespace 20 | rename_column :active_admin_comments, :author_id, :admin_user_id 21 | rename_column :active_admin_comments, :author_type, :admin_user_type 22 | rename_table :active_admin_comments, :admin_notes 23 | add_index :admin_notes, [:admin_user_type, :admin_user_id] 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/active_admin/editor/config.rb: -------------------------------------------------------------------------------- 1 | require 'logger' 2 | 3 | module ActiveAdmin 4 | module Editor 5 | class << self 6 | # Returns the current Configuration 7 | def configuration 8 | @configuration ||= Configuration.new 9 | end 10 | 11 | # Yields the Configuration 12 | def configure 13 | yield configuration 14 | end 15 | end 16 | 17 | class Configuration 18 | # AWS credentials 19 | attr_accessor :aws_access_key_id 20 | attr_accessor :aws_access_secret 21 | 22 | # The s3 bucket to store uploads. 23 | attr_accessor :s3_bucket 24 | 25 | # Base directory to store the uploaded files in the bucket. Defaults to 26 | # 'uploads'. 27 | attr_accessor :storage_dir 28 | 29 | # wysiwyg stylesheets that get included in the backend and the frontend. 30 | attr_accessor :stylesheets 31 | 32 | def storage_dir 33 | @storage_dir ||= 'uploads' 34 | end 35 | 36 | def storage_dir=(dir) 37 | @storage_dir = dir.to_s.gsub(/(^\/|\/$)/, '') 38 | end 39 | 40 | def stylesheets 41 | @stylesheets ||= [ 'active_admin/editor/wysiwyg.css' ] 42 | end 43 | 44 | def s3_configured? 45 | aws_access_key_id.present? && 46 | aws_access_secret.present? && 47 | s3_bucket.present? 48 | end 49 | 50 | def parser_rules 51 | @parser_rules ||= PARSER_RULES.dup 52 | end 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /spec/lib/config_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe ActiveAdmin::Editor.configuration do 4 | let(:configuration) { described_class } 5 | 6 | after do 7 | configuration.aws_access_key_id = nil 8 | configuration.aws_access_secret = nil 9 | configuration.s3_bucket = nil 10 | configuration.storage_dir = 'uploads' 11 | end 12 | 13 | context 'by default' do 14 | its(:aws_access_key_id) { should be_nil } 15 | its(:aws_access_secret) { should be_nil } 16 | its(:s3_bucket) { should be_nil } 17 | its(:storage_dir) { should eq 'uploads' } 18 | end 19 | 20 | describe '.s3_configured?' do 21 | subject { configuration.s3_configured? } 22 | 23 | context 'when not configured' do 24 | before do 25 | end 26 | 27 | it { should be_false } 28 | end 29 | 30 | context 'when key, secret and bucket are set' do 31 | before do 32 | configuration.aws_access_key_id = 'foo' 33 | configuration.aws_access_secret = 'bar' 34 | configuration.s3_bucket = 'bucket' 35 | end 36 | 37 | it { should be_true } 38 | end 39 | end 40 | 41 | describe '.storage_dir' do 42 | subject { configuration.storage_dir } 43 | 44 | it 'strips trailing slashes' do 45 | configuration.storage_dir = 'uploads/' 46 | expect(subject).to eq 'uploads' 47 | end 48 | 49 | it 'strips leading slashes' do 50 | configuration.storage_dir = '/uploads' 51 | expect(subject).to eq 'uploads' 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Raise exception on mass assignment protection for Active Record models 26 | config.active_record.mass_assignment_sanitizer = :strict 27 | 28 | # Log the query plan for queries taking more than this (works 29 | # with SQLite, MySQL, and PostgreSQL) 30 | config.active_record.auto_explain_threshold_in_seconds = 0.5 31 | 32 | # Do not compress assets 33 | config.assets.compress = false 34 | 35 | # Expands the lines which load the assets 36 | config.assets.debug = true 37 | end 38 | -------------------------------------------------------------------------------- /active_admin_editor.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path('../lib', __FILE__) 2 | 3 | # Maintain your gem's version: 4 | require 'active_admin/editor/version' 5 | 6 | # Describe your gem and declare its dependencies: 7 | Gem::Specification.new do |s| 8 | s.name = 'active_admin_editor' 9 | s.version = ActiveAdmin::Editor::VERSION 10 | s.authors = ['Eric Holmes'] 11 | s.email = ['eric@ejholmes.net'] 12 | s.homepage = 'https://github.com/ejholmes/active_admin_editor' 13 | s.summary = 'Rich text editor for Active Admin using wysihtml5.' 14 | s.description = s.summary 15 | 16 | s.files = Dir['{app,config,db,lib,vendor}/**/*'] + ['MIT-LICENSE', 'Rakefile', 'README.md'] 17 | s.test_files = Dir['spec/**/*'] 18 | 19 | s.add_dependency 'rails', '>= 3.0.0' 20 | s.add_dependency 'activeadmin', '>= 0.4.0' 21 | s.add_dependency 'ejs' 22 | 23 | s.add_development_dependency 'sqlite3' 24 | s.add_development_dependency 'rspec', '~> 2.12.0' 25 | s.add_development_dependency 'rspec-rails', '~> 2.12.0' 26 | s.add_development_dependency 'factory_girl_rails' 27 | s.add_development_dependency 'database_cleaner', '~> 0.9.1' 28 | s.add_development_dependency 'capybara', '~> 1.1.4' 29 | s.add_development_dependency 'activeadmin', '~> 0.4.3' 30 | s.add_development_dependency 'poltergeist', '~> 1.0.2' 31 | s.add_development_dependency 'faker' 32 | 33 | # JavaScript 34 | s.add_development_dependency 'konacha', '~> 2.1.0' 35 | s.add_development_dependency 'chai-jquery-rails' 36 | s.add_development_dependency 'sinon-chai-rails' 37 | s.add_development_dependency 'sinon-rails' 38 | end 39 | -------------------------------------------------------------------------------- /spec/lib/policy_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe ActiveAdmin::Editor::Policy do 4 | let(:configuration) { double('configuration') } 5 | 6 | before do 7 | subject.stub(:configuration).and_return(configuration) 8 | end 9 | 10 | describe '.document' do 11 | before do 12 | configuration.should_receive(:s3_bucket).and_return('bucket') 13 | configuration.should_receive(:storage_dir).and_return('uploads') 14 | end 15 | 16 | it 'base64 encodes the content' do 17 | Base64.should_receive(:encode64).and_return("foobar\n") 18 | expect(subject.document).to eq 'foobar' 19 | end 20 | 21 | it 'caches the document' do 22 | Base64.should_receive(:encode64).once.and_call_original 23 | 2.times { subject.document } 24 | end 25 | end 26 | 27 | describe '.signature' do 28 | before do 29 | configuration.should_receive(:s3_bucket).and_return('bucket') 30 | configuration.should_receive(:storage_dir).and_return('uploads') 31 | configuration.should_receive(:aws_access_secret).and_return('secret') 32 | end 33 | 34 | it 'base64 encodes the content' do 35 | Base64.should_receive(:encode64).twice.and_return("whizbang\n") 36 | expect(subject.signature).to eq 'whizbang' 37 | end 38 | end 39 | 40 | describe '.to_json' do 41 | before do 42 | subject.stub(:document).and_return('doc') 43 | subject.stub(:signature).and_return('sig') 44 | end 45 | 46 | it 'should be a json representation of the document and signature' do 47 | expect(subject.to_json).to eq({ :document => 'doc', :signature => 'sig' }.to_json) 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Raise exception on mass assignment protection for Active Record models 33 | config.active_record.mass_assignment_sanitizer = :strict 34 | 35 | # Print deprecation notices to the stderr 36 | config.active_support.deprecation = :stderr 37 | end 38 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_admin/editor.css.scss: -------------------------------------------------------------------------------- 1 | @import 'active_admin/mixins'; 2 | 3 | body form .html_editor { 4 | .wrap { 5 | width: 76%; 6 | float: left; 7 | } 8 | 9 | &.uploading .spinner { 10 | display: inline; 11 | } 12 | 13 | .spinner { 14 | display: none; 15 | } 16 | 17 | textarea { 18 | @include rounded-bottom; 19 | line-height: 1.5em; 20 | width: 100%; 21 | height: 300px; 22 | border-top: 1px solid lighten(#C9D0D6, 10%); 23 | 24 | &:focus { 25 | box-shadow: none; 26 | border: 1px solid #C9D0D6; 27 | border-top: 1px solid lighten(#C9D0D6, 10%); 28 | } 29 | } 30 | 31 | .toolbar { 32 | width: 100%; 33 | padding: 0 10px; 34 | border: 1px solid #C9D0D6; 35 | border-bottom: none; 36 | @include rounded-top; 37 | background: #fff; 38 | 39 | ul li a { 40 | display: block; 41 | padding: 5px 10px; 42 | text-decoration: none; 43 | color: #999; 44 | 45 | &.wysihtml5-command-active, 46 | &.wysihtml5-action-active, 47 | &.wysihtml5-command-dialog-opened { 48 | text-decoration: underline; 49 | color: $link-color; 50 | } 51 | } 52 | 53 | ul li { 54 | display: inline-block; 55 | 56 | &:first-child a { 57 | padding-left: 0; 58 | } 59 | } 60 | 61 | &.wysihtml5-commands-disabled ul li a[data-wysihtml5-command] { 62 | display: none; 63 | } 64 | } 65 | 66 | .dialog { 67 | border-top: 1px solid lighten(#C9D0D6, 10%); 68 | padding: 10px 20px; 69 | margin: 0 -10px; 70 | 71 | label { 72 | margin-bottom: 10px; 73 | width: 300px; 74 | 75 | input { 76 | display: block; 77 | } 78 | 79 | select { 80 | display: block; 81 | } 82 | } 83 | 84 | .action-group { 85 | display: block; 86 | float: right; 87 | margin-top: 5px; 88 | clear: both; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20121224200148_devise_create_admin_users.rb: -------------------------------------------------------------------------------- 1 | class DeviseCreateAdminUsers < ActiveRecord::Migration 2 | def change 3 | create_table(:admin_users) do |t| 4 | ## Database authenticatable 5 | t.string :email, :null => false, :default => "" 6 | t.string :encrypted_password, :null => false, :default => "" 7 | 8 | ## Recoverable 9 | t.string :reset_password_token 10 | t.datetime :reset_password_sent_at 11 | 12 | ## Rememberable 13 | t.datetime :remember_created_at 14 | 15 | ## Trackable 16 | t.integer :sign_in_count, :default => 0 17 | t.datetime :current_sign_in_at 18 | t.datetime :last_sign_in_at 19 | t.string :current_sign_in_ip 20 | t.string :last_sign_in_ip 21 | 22 | ## Encryptable 23 | # t.string :password_salt 24 | 25 | ## Confirmable 26 | # t.string :confirmation_token 27 | # t.datetime :confirmed_at 28 | # t.datetime :confirmation_sent_at 29 | # t.string :unconfirmed_email # Only if using reconfirmable 30 | 31 | ## Lockable 32 | # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts 33 | # t.string :unlock_token # Only if unlock strategy is :email or :both 34 | # t.datetime :locked_at 35 | 36 | ## Token authenticatable 37 | # t.string :authentication_token 38 | 39 | 40 | t.timestamps 41 | end 42 | 43 | # Create a default user 44 | AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') 45 | 46 | add_index :admin_users, :email, :unique => true 47 | add_index :admin_users, :reset_password_token, :unique => true 48 | # add_index :admin_users, :confirmation_token, :unique => true 49 | # add_index :admin_users, :unlock_token, :unique => true 50 | # add_index :admin_users, :authentication_token, :unique => true 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_admin/editor/wysiwyg.css: -------------------------------------------------------------------------------- 1 | 2 | .wysiwyg-font-size-smaller { 3 | font-size: smaller; 4 | } 5 | 6 | .wysiwyg-font-size-larger { 7 | font-size: larger; 8 | } 9 | 10 | .wysiwyg-font-size-xx-large { 11 | font-size: xx-large; 12 | } 13 | 14 | .wysiwyg-font-size-x-large { 15 | font-size: x-large; 16 | } 17 | 18 | .wysiwyg-font-size-large { 19 | font-size: large; 20 | } 21 | 22 | .wysiwyg-font-size-medium { 23 | font-size: medium; 24 | } 25 | 26 | .wysiwyg-font-size-small { 27 | font-size: small; 28 | } 29 | 30 | .wysiwyg-font-size-x-small { 31 | font-size: x-small; 32 | } 33 | 34 | .wysiwyg-font-size-xx-small { 35 | font-size: xx-small; 36 | } 37 | 38 | .wysiwyg-color-black { 39 | color: black; 40 | } 41 | 42 | .wysiwyg-color-silver { 43 | color: silver; 44 | } 45 | 46 | .wysiwyg-color-gray { 47 | color: gray; 48 | } 49 | 50 | .wysiwyg-color-white { 51 | color: white; 52 | } 53 | 54 | .wysiwyg-color-maroon { 55 | color: maroon; 56 | } 57 | 58 | .wysiwyg-color-red { 59 | color: red; 60 | } 61 | 62 | .wysiwyg-color-purple { 63 | color: purple; 64 | } 65 | 66 | .wysiwyg-color-fuchsia { 67 | color: fuchsia; 68 | } 69 | 70 | .wysiwyg-color-green { 71 | color: green; 72 | } 73 | 74 | .wysiwyg-color-lime { 75 | color: lime; 76 | } 77 | 78 | .wysiwyg-color-olive { 79 | color: olive; 80 | } 81 | 82 | .wysiwyg-color-yellow { 83 | color: yellow; 84 | } 85 | 86 | .wysiwyg-color-navy { 87 | color: navy; 88 | } 89 | 90 | .wysiwyg-color-blue { 91 | color: blue; 92 | } 93 | 94 | .wysiwyg-color-teal { 95 | color: teal; 96 | } 97 | 98 | .wysiwyg-color-aqua { 99 | color: aqua; 100 | } 101 | 102 | .wysiwyg-text-align-right { 103 | text-align: right; 104 | } 105 | 106 | .wysiwyg-text-align-center { 107 | text-align: center; 108 | } 109 | 110 | .wysiwyg-text-align-left { 111 | text-align: left; 112 | } 113 | 114 | .wysiwyg-float-left { 115 | float: left; 116 | margin: 0 8px 8px 0; 117 | } 118 | 119 | .wysiwyg-float-right { 120 | float: right; 121 | margin: 0 0 8px 8px; 122 | } 123 | 124 | .wysiwyg-clear-right { 125 | clear: right; 126 | } 127 | 128 | .wysiwyg-clear-left { 129 | clear: left; 130 | } 131 | -------------------------------------------------------------------------------- /lib/active_admin/editor/policy.rb: -------------------------------------------------------------------------------- 1 | require 'base64' 2 | require 'openssl' 3 | require 'digest/sha1' 4 | require 'json' 5 | 6 | module ActiveAdmin 7 | module Editor 8 | # Public: Class used to generate a new S3 policy document, which can be 9 | # used to authorize a direct upload to an S3 bucket. 10 | # 11 | # Examples 12 | # 13 | # policy = Policy.new 14 | # # => # 15 | # 16 | # policy.document 17 | # # => "eyJleHBpcmF0aW9uIjo...gwMDBdXX0=" 18 | # 19 | # policy.signature 20 | # # => "NakHRb4SaI8cpU5RtSVh25kj/sc=" 21 | # 22 | class Policy 23 | 24 | # Public: The base64 encoded policy document. 25 | def document 26 | @document ||= Base64.encode64(document_hash.to_json).gsub("\n", '') 27 | end 28 | 29 | # Public: The base64 encoded signature of the policy document. Signed 30 | # with the s3 access secret. 31 | def signature 32 | @signature ||= Base64.encode64(digest).gsub("\n", '') 33 | end 34 | 35 | # Public: JSON representation of the policy. 36 | def to_json 37 | { :document => document, :signature => signature }.to_json 38 | end 39 | 40 | private 41 | 42 | # Internal: The policy document. 43 | def document_hash 44 | { :expiration => Time.now.utc + 1.hour, 45 | :conditions => [ 46 | { :bucket => bucket }, 47 | [ 'starts-with', '$key', storage_dir ], 48 | { :acl => 'public-read' }, 49 | [ 'starts-with', '$Content-Type', '' ], 50 | [ 'content-length-range', 0, 524288000 ] 51 | ] 52 | } 53 | end 54 | 55 | # Internal: Generates and HMAC digest of the document, signed with the 56 | # access secret. 57 | def digest 58 | OpenSSL::HMAC.digest( 59 | OpenSSL::Digest::Digest.new('sha1'), 60 | secret, 61 | document 62 | ) 63 | end 64 | 65 | def storage_dir 66 | configuration.storage_dir + '/' 67 | end 68 | 69 | def bucket 70 | configuration.s3_bucket 71 | end 72 | 73 | def secret 74 | configuration.aws_access_secret 75 | end 76 | 77 | def configuration 78 | ActiveAdmin::Editor.configuration 79 | end 80 | 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /app/assets/javascripts/active_admin/editor/templates/toolbar.jst.ejs: -------------------------------------------------------------------------------- 1 |
    2 | 16 | 17 | 28 | 29 | 48 | 49 |
    50 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Don't fallback to assets pipeline if a precompiled asset is missed 18 | config.assets.compile = false 19 | 20 | # Generate digests for assets URLs 21 | config.assets.digest = true 22 | 23 | # Defaults to nil and saved in location specified by config.assets.prefix 24 | # config.assets.manifest = YOUR_PATH 25 | 26 | # Specifies the header that your server uses for sending files 27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | # config.force_ssl = true 32 | 33 | # See everything in the log (default is :info) 34 | # config.log_level = :debug 35 | 36 | # Prepend all log lines with the following tags 37 | # config.log_tags = [ :subdomain, :uuid ] 38 | 39 | # Use a different logger for distributed setups 40 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 41 | 42 | # Use a different cache store in production 43 | # config.cache_store = :mem_cache_store 44 | 45 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 46 | # config.action_controller.asset_host = "http://assets.example.com" 47 | 48 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 49 | # config.assets.precompile += %w( search.js ) 50 | 51 | # Disable delivery errors, bad email addresses will be ignored 52 | # config.action_mailer.raise_delivery_errors = false 53 | 54 | # Enable threaded mode 55 | # config.threadsafe! 56 | 57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 58 | # the I18n.default_locale when a translation can not be found) 59 | config.i18n.fallbacks = true 60 | 61 | # Send deprecation notices to registered listeners 62 | config.active_support.deprecation = :notify 63 | 64 | # Log the query plan for queries taking more than this (works 65 | # with SQLite, MySQL, and PostgreSQL) 66 | # config.active_record.auto_explain_threshold_in_seconds = 0.5 67 | end 68 | -------------------------------------------------------------------------------- /spec/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | Bundler.require 6 | require 'active_admin_editor' 7 | 8 | module Dummy 9 | class Application < Rails::Application 10 | # Settings in config/environments/* take precedence over those specified here. 11 | # Application configuration should go into files in config/initializers 12 | # -- all .rb files in that directory are automatically loaded. 13 | 14 | # Custom directories with classes and modules you want to be autoloadable. 15 | # config.autoload_paths += %W(#{config.root}/extras) 16 | 17 | # Only load the plugins named here, in the order given (default is alphabetical). 18 | # :all can be used as a placeholder for all plugins not explicitly named. 19 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 20 | 21 | # Activate observers that should always be running. 22 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 23 | 24 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 25 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 26 | # config.time_zone = 'Central Time (US & Canada)' 27 | 28 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 29 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 30 | # config.i18n.default_locale = :de 31 | 32 | # Configure the default encoding used in templates for Ruby 1.9. 33 | config.encoding = "utf-8" 34 | 35 | # Configure sensitive parameters which will be filtered from the log file. 36 | config.filter_parameters += [:password] 37 | 38 | # Enable escaping HTML in JSON. 39 | config.active_support.escape_html_entities_in_json = true 40 | 41 | # Use SQL instead of Active Record's schema dumper when creating the database. 42 | # This is necessary if your schema can't be completely dumped by the schema dumper, 43 | # like if you have constraints or database-specific column types 44 | # config.active_record.schema_format = :sql 45 | 46 | # Enforce whitelist mode for mass assignment. 47 | # This will create an empty whitelist of attributes available for mass-assignment for all models 48 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 49 | # parameters by using an attr_accessible or attr_protected declaration. 50 | config.active_record.whitelist_attributes = true 51 | 52 | # Enable the asset pipeline 53 | config.assets.enabled = true 54 | 55 | # Version of your assets, change this if you want to expire all your assets 56 | config.assets.version = '1.0' 57 | end 58 | end 59 | 60 | -------------------------------------------------------------------------------- /spec/dummy/db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended to check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(:version => 20121224200305) do 15 | 16 | create_table "active_admin_comments", :force => true do |t| 17 | t.string "resource_id", :null => false 18 | t.string "resource_type", :null => false 19 | t.integer "author_id" 20 | t.string "author_type" 21 | t.text "body" 22 | t.datetime "created_at", :null => false 23 | t.datetime "updated_at", :null => false 24 | t.string "namespace" 25 | end 26 | 27 | add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id" 28 | add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace" 29 | add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id" 30 | 31 | create_table "admin_users", :force => true do |t| 32 | t.string "email", :default => "", :null => false 33 | t.string "encrypted_password", :default => "", :null => false 34 | t.string "reset_password_token" 35 | t.datetime "reset_password_sent_at" 36 | t.datetime "remember_created_at" 37 | t.integer "sign_in_count", :default => 0 38 | t.datetime "current_sign_in_at" 39 | t.datetime "last_sign_in_at" 40 | t.string "current_sign_in_ip" 41 | t.string "last_sign_in_ip" 42 | t.datetime "created_at", :null => false 43 | t.datetime "updated_at", :null => false 44 | end 45 | 46 | add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true 47 | add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true 48 | 49 | create_table "pages", :force => true do |t| 50 | t.string "title" 51 | t.text "content" 52 | t.datetime "created_at", :null => false 53 | t.datetime "updated_at", :null => false 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /spec/dummy/config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | errors: 5 | messages: 6 | expired: "has expired, please request a new one" 7 | not_found: "not found" 8 | already_confirmed: "was already confirmed, please try signing in" 9 | not_locked: "was not locked" 10 | not_saved: 11 | one: "1 error prohibited this %{resource} from being saved:" 12 | other: "%{count} errors prohibited this %{resource} from being saved:" 13 | 14 | devise: 15 | failure: 16 | already_authenticated: 'You are already signed in.' 17 | unauthenticated: 'You need to sign in or sign up before continuing.' 18 | unconfirmed: 'You have to confirm your account before continuing.' 19 | locked: 'Your account is locked.' 20 | invalid: 'Invalid email or password.' 21 | invalid_token: 'Invalid authentication token.' 22 | timeout: 'Your session expired, please sign in again to continue.' 23 | inactive: 'Your account was not activated yet.' 24 | sessions: 25 | signed_in: 'Signed in successfully.' 26 | signed_out: 'Signed out successfully.' 27 | passwords: 28 | send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.' 29 | updated: 'Your password was changed successfully. You are now signed in.' 30 | updated_not_active: 'Your password was changed successfully.' 31 | send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail" 32 | confirmations: 33 | send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' 34 | send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.' 35 | confirmed: 'Your account was successfully confirmed. You are now signed in.' 36 | registrations: 37 | signed_up: 'Welcome! You have signed up successfully.' 38 | signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' 39 | signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' 40 | signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.' 41 | updated: 'You updated your account successfully.' 42 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." 43 | destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' 44 | unlocks: 45 | send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' 46 | unlocked: 'Your account has been unlocked successfully. Please sign in to continue.' 47 | send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.' 48 | omniauth_callbacks: 49 | success: 'Successfully authorized from %{kind} account.' 50 | failure: 'Could not authorize you from %{kind} because "%{reason}".' 51 | mailer: 52 | confirmation_instructions: 53 | subject: 'Confirmation instructions' 54 | reset_password_instructions: 55 | subject: 'Reset password instructions' 56 | unlock_instructions: 57 | subject: 'Unlock Instructions' 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Active Admin Editor 2 | [![Build Status](https://travis-ci.org/ejholmes/active_admin_editor.png?branch=master)](https://travis-ci.org/ejholmes/active_admin_editor) [![Code Climate](https://codeclimate.com/github/ejholmes/active_admin_editor.png)](https://codeclimate.com/github/ejholmes/active_admin_editor) 3 | 4 | This is a wysiwyg html editor for the [Active Admin](http://activeadmin.info/) 5 | interface using [wysihtml5](https://github.com/xing/wysihtml5). 6 | 7 | ![screenshot](https://dl.dropbox.com/u/1906634/Captured/OhvTv.png) 8 | 9 | [Demo](http://active-admin-editor-demo.herokuapp.com/admin/pages/new) 10 | 11 | ## Installation 12 | 13 | Add the following to your `Gemfile`: 14 | 15 | ```ruby 16 | gem 'active_admin_editor' 17 | ``` 18 | 19 | And include the wysiwyg styles in your `application.css`: 20 | 21 | ```scss 22 | //= require active_admin/editor/wysiwyg 23 | ``` 24 | 25 | Then run the following to install the default intializer: 26 | 27 | ```bash 28 | $ rails g active_admin:editor 29 | ``` 30 | 31 | ## Usage 32 | 33 | This gem provides you with a custom formtastic input called `:html_editor` to build out a wysihtml5 enabled input. 34 | All you have to do is specify the `:as` option for your inputs. 35 | 36 | **Example** 37 | 38 | ```ruby 39 | ActiveAdmin.register Page do 40 | form do |f| 41 | f.inputs do 42 | f.input :title 43 | f.input :content, as: :html_editor 44 | end 45 | 46 | f.buttons 47 | end 48 | end 49 | ``` 50 | 51 | ## Uploads 52 | 53 | The editor supports uploading of assets directly to an S3 bucket. Edit the initializer that 54 | was installed when you ran `rails g active_admin:editor`. 55 | 56 | ```ruby 57 | ActiveAdmin::Editor.configure do |config| 58 | config.s3_bucket = '' 59 | config.aws_access_key_id = '' 60 | config.aws_access_secret = '' 61 | # config.storage_dir = 'uploads' 62 | end 63 | ``` 64 | 65 | Then add the following CORS configuration to the S3 bucket: 66 | 67 | ```xml 68 | 69 | 70 | 71 | * 72 | PUT 73 | POST 74 | GET 75 | HEAD 76 | 3000 77 | Location 78 | * 79 | 80 | 81 | ``` 82 | 83 | ## Configuration 84 | 85 | You can configure the editor in the initializer installed with `rails g 86 | active_admin:editor` or you can configure the editor during 87 | `ActiveAdmin.setup`: 88 | 89 | ```ruby 90 | ActiveAdmin.setup do |config| 91 | # ... 92 | config.editor.aws_access_key_id = '' 93 | config.editor.s3_bucket = 'bucket' 94 | end 95 | ``` 96 | 97 | ## Parser Rules 98 | 99 | [Parser rules](https://github.com/xing/wysihtml5/tree/master/parser_rules) can 100 | be configured through the initializer: 101 | 102 | ```ruby 103 | ActiveAdmin::Editor.configure do |config| 104 | config.parser_rules['tags']['strike'] = { 105 | 'remove' => 0 106 | } 107 | end 108 | ``` 109 | 110 | Be sure to clear your rails cache after changing the config: 111 | 112 | ```bash 113 | rm -rf tmp/cache 114 | ``` 115 | 116 | ## Heroku 117 | 118 | Since some of the javascript files need to be compiled with access to the env 119 | vars, it's recommended that you add the [user-env-compile](https://devcenter.heroku.com/articles/labs-user-env-compile) 120 | labs feature to your app. 121 | 122 | 1. Tell your rails app to run initializers on asset compilation 123 | 124 | ```ruby 125 | # config/environments/production.rb 126 | config.initialize_on_precompile = true 127 | ``` 128 | 2. Add the labs feature 129 | 130 | ```bash 131 | heroku labs:enable user-env-compile -a myapp 132 | ``` 133 | 134 | ## Contributing 135 | 136 | 1. Fork it 137 | 2. Create your feature branch (`git checkout -b my-new-feature`) 138 | 3. Commit your changes (`git commit -am 'Added some feature'`) 139 | 4. Push to the branch (`git push origin my-new-feature`) 140 | 5. Create new Pull Request 141 | 142 | ### Tests 143 | 144 | Run RSpec tests with `bundle exec rake`. Run JavaScript specs with `bundle 145 | exec rake konacha:serve`. 146 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/active_admin.rb: -------------------------------------------------------------------------------- 1 | ActiveAdmin.setup do |config| 2 | 3 | # == Site Title 4 | # 5 | # Set the title that is displayed on the main layout 6 | # for each of the active admin pages. 7 | # 8 | config.site_title = "Dummy" 9 | 10 | # Set the link url for the title. For example, to take 11 | # users to your main site. Defaults to no link. 12 | # 13 | # config.site_title_link = "/" 14 | 15 | # Set an optional image to be displayed for the header 16 | # instead of a string (overrides :site_title) 17 | # 18 | # Note: Recommended image height is 21px to properly fit in the header 19 | # 20 | # config.site_title_image = "/images/logo.png" 21 | 22 | # == Default Namespace 23 | # 24 | # Set the default namespace each administration resource 25 | # will be added to. 26 | # 27 | # eg: 28 | # config.default_namespace = :hello_world 29 | # 30 | # This will create resources in the HelloWorld module and 31 | # will namespace routes to /hello_world/* 32 | # 33 | # To set no namespace by default, use: 34 | # config.default_namespace = false 35 | # 36 | # Default: 37 | # config.default_namespace = :admin 38 | # 39 | # You can customize the settings for each namespace by using 40 | # a namespace block. For example, to change the site title 41 | # within a namespace: 42 | # 43 | # config.namespace :admin do |admin| 44 | # admin.site_title = "Custom Admin Title" 45 | # end 46 | # 47 | # This will ONLY change the title for the admin section. Other 48 | # namespaces will continue to use the main "site_title" configuration. 49 | 50 | # == User Authentication 51 | # 52 | # Active Admin will automatically call an authentication 53 | # method in a before filter of all controller actions to 54 | # ensure that there is a currently logged in admin user. 55 | # 56 | # This setting changes the method which Active Admin calls 57 | # within the controller. 58 | config.authentication_method = :authenticate_admin_user! 59 | 60 | 61 | # == Current User 62 | # 63 | # Active Admin will associate actions with the current 64 | # user performing them. 65 | # 66 | # This setting changes the method which Active Admin calls 67 | # to return the currently logged in user. 68 | config.current_user_method = :current_admin_user 69 | 70 | 71 | # == Logging Out 72 | # 73 | # Active Admin displays a logout link on each screen. These 74 | # settings configure the location and method used for the link. 75 | # 76 | # This setting changes the path where the link points to. If it's 77 | # a string, the strings is used as the path. If it's a Symbol, we 78 | # will call the method to return the path. 79 | # 80 | # Default: 81 | config.logout_link_path = :destroy_admin_user_session_path 82 | 83 | # This setting changes the http method used when rendering the 84 | # link. For example :get, :delete, :put, etc.. 85 | # 86 | # Default: 87 | # config.logout_link_method = :get 88 | 89 | 90 | # == Admin Comments 91 | # 92 | # Admin comments allow you to add comments to any model for admin use. 93 | # Admin comments are enabled by default. 94 | # 95 | # Default: 96 | # config.allow_comments = true 97 | # 98 | # You can turn them on and off for any given namespace by using a 99 | # namespace config block. 100 | # 101 | # Eg: 102 | # config.namespace :without_comments do |without_comments| 103 | # without_comments.allow_comments = false 104 | # end 105 | 106 | 107 | # == Controller Filters 108 | # 109 | # You can add before, after and around filters to all of your 110 | # Active Admin resources from here. 111 | # 112 | # config.before_filter :do_something_awesome 113 | 114 | 115 | # == Register Stylesheets & Javascripts 116 | # 117 | # We recommend using the built in Active Admin layout and loading 118 | # up your own stylesheets / javascripts to customize the look 119 | # and feel. 120 | # 121 | # To load a stylesheet: 122 | # config.register_stylesheet 'my_stylesheet.css' 123 | # 124 | # You can provide an options hash for more control, which is passed along to stylesheet_link_tag(): 125 | # config.register_stylesheet 'my_print_stylesheet.css', :media => :print 126 | # 127 | # To load a javascript file: 128 | # config.register_javascript 'my_javascript.js' 129 | 130 | config.editor.s3_bucket = ENV['S3_BUCKET'] 131 | config.editor.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID'] 132 | config.editor.aws_access_secret = ENV['AWS_ACCESS_SECRET'] 133 | config.editor.parser_rules['tags']['strike'] = { 134 | 'remove' => 0 135 | } 136 | end 137 | -------------------------------------------------------------------------------- /app/assets/javascripts/active_admin/editor/editor.js: -------------------------------------------------------------------------------- 1 | //= require_tree ./templates 2 | 3 | ;(function(window, wysihtml5) { 4 | window.AA = (window.AA || {}) 5 | var config 6 | 7 | var Editor = function(options, el) { 8 | config = options 9 | var _this = this 10 | this.$el = $(el) 11 | this.$textarea = this.$el.find('textarea') 12 | this.policy = this.$el.data('policy') 13 | 14 | this._addToolbar() 15 | this._attachEditor() 16 | } 17 | 18 | /** 19 | * Returns the wysihtml5 editor instance for this editor. 20 | */ 21 | Editor.prototype.editor = function() { 22 | return this._editor 23 | } 24 | 25 | /** 26 | * Adds the wysihtml5 toolbar. If uploads are enabled, also adds the 27 | * necessary file inputs for uploading. 28 | */ 29 | Editor.prototype._addToolbar = function() { 30 | var template = JST['active_admin/editor/templates/toolbar']({ 31 | id: this.$el.attr('id') + '-toolbar' 32 | }) 33 | 34 | this.$toolbar = $(template) 35 | 36 | if (config.uploads_enabled) { 37 | var _this = this 38 | this.$toolbar.find('input.uploadable').each(function() { 39 | _this._addUploader(this) 40 | }) 41 | } 42 | 43 | this.$el.find('.wrap').prepend(this.$toolbar) 44 | } 45 | 46 | /** 47 | * Adds a file input attached to the supplied text input. And upload is 48 | * triggered if the source of the input is changed. 49 | * 50 | * @input Text input to attach a file input to. 51 | */ 52 | Editor.prototype._addUploader = function(input) { 53 | var $input = $(input) 54 | 55 | var template = JST['active_admin/editor/templates/uploader']({ spinner: config.spinner }) 56 | var $uploader = $(template) 57 | 58 | var $dialog = $input.closest('[data-wysihtml5-dialog]') 59 | $dialog.append($uploader) 60 | 61 | var _this = this 62 | $uploader.find('input:file').on('change', function() { 63 | var file = this.files[0] 64 | if (file) { 65 | $input.val('') 66 | _this.upload(file, function(location) { 67 | $input.val(location) 68 | }) 69 | } 70 | }) 71 | } 72 | 73 | /** 74 | * Initializes the wysihtml5 editor for the textarea. 75 | */ 76 | Editor.prototype._attachEditor = function() { 77 | this._editor = new wysihtml5.Editor(this.$textarea.attr('id'), { 78 | toolbar: this.$toolbar.attr('id'), 79 | stylesheets: config.stylesheets, 80 | parserRules: config.parserRules 81 | }) 82 | } 83 | 84 | /** 85 | * Sets the internal uploading state to true or false. Adds the .uploading 86 | * class to the root element for stying. 87 | * 88 | * @uploading {Boolean} Whether or not something is being uploaded. 89 | */ 90 | Editor.prototype._uploading = function(uploading) { 91 | this.__uploading = uploading 92 | this.$el.toggleClass('uploading', this.__uploading) 93 | return this.__uploading 94 | } 95 | 96 | /** 97 | * Uploads a file to S3. When the upload is complete, calls callback with the 98 | * location of the uploaded file. 99 | * 100 | * @file The file to upload 101 | * @callback A function to be called when the upload completes. 102 | */ 103 | Editor.prototype.upload = function(file, callback) { 104 | var _this = this 105 | _this._uploading(true) 106 | 107 | var xhr = new XMLHttpRequest() 108 | , fd = new FormData() 109 | , key = config.storage_dir + '/' + Date.now().toString() + '-' + file.name 110 | 111 | fd.append('key', key) 112 | fd.append('AWSAccessKeyId', config.aws_access_key_id) 113 | fd.append('acl', 'public-read') 114 | fd.append('policy', this.policy.document) 115 | fd.append('signature', this.policy.signature) 116 | fd.append('Content-Type', file.type) 117 | fd.append('file', file) 118 | 119 | xhr.upload.addEventListener('progress', function(e) { 120 | _this.loaded = e.loaded 121 | _this.total = e.total 122 | _this.progress = e.loaded / e.total 123 | }, false) 124 | 125 | xhr.onreadystatechange = function() { 126 | if (xhr.readyState != 4) { return } 127 | _this._uploading(false) 128 | if (xhr.status == 204) { 129 | callback(xhr.getResponseHeader('Location')) 130 | } else { 131 | alert('Failed to upload file. Have you configured S3 properly?') 132 | } 133 | } 134 | 135 | xhr.open('POST', 'https://' + config.s3_bucket + '.s3.amazonaws.com', true) 136 | xhr.send(fd) 137 | 138 | return xhr 139 | } 140 | 141 | window.AA.Editor = Editor 142 | })(window, wysihtml5) 143 | 144 | ;(function(window, $) { 145 | if ($.widget) { 146 | $.widget.bridge('editor', window.AA.Editor) 147 | } 148 | })(window, jQuery) 149 | -------------------------------------------------------------------------------- /spec/javascripts/editor_spec.js: -------------------------------------------------------------------------------- 1 | //= require spec_helper 2 | //= require support/mock_wysihtml5 3 | //= require active_admin/editor/editor 4 | 5 | describe('Editor', function() { 6 | beforeEach(function() { 7 | this.xhr = sinon.useFakeXMLHttpRequest() 8 | $('body').append(JST['templates/editor']()) 9 | this.config = sinon.stub() 10 | this.editor = new window.AA.Editor(this.config, $('.html_editor')) 11 | }) 12 | 13 | afterEach(function() { 14 | this.xhr.restore() 15 | }) 16 | 17 | it('sets .$el', function() { 18 | expect(this.editor.$el).to.exist 19 | }) 20 | 21 | it('sets .$textarea', function() { 22 | expect(this.editor.$textarea).to.exist 23 | }) 24 | 25 | it('sets .$toolbar', function() { 26 | expect(this.editor.$toolbar).to.exist 27 | }) 28 | 29 | it('sets .policy', function() { 30 | expect(this.editor.policy.document).to.eq('policy document') 31 | }) 32 | 33 | it('sets .signature', function() { 34 | expect(this.editor.policy.signature).to.eq('policy signature') 35 | }) 36 | 37 | it('attaches wysihtml5', function() { 38 | expect(wysihtml5.Editor).to.have.been.calledWith('page_content') 39 | }) 40 | 41 | describe('.editor', function() { 42 | it('returns the wysihtml5 editor', function() { 43 | expect(this.editor.editor()).to.eq(this.editor._editor) 44 | }) 45 | }) 46 | 47 | describe('._uploading', function() { 48 | describe('when set to true', function() { 49 | beforeEach(function() { 50 | this.uploading = this.editor._uploading(true) 51 | }) 52 | 53 | it('returns true', function() { 54 | expect(this.uploading).to.be.true 55 | }) 56 | 57 | it('sets ._uploading', function() { 58 | expect(this.editor.__uploading).to.be.true 59 | }) 60 | 61 | it('adds the .uploading class', function() { 62 | expect(this.editor.$el).to.have.class('uploading') 63 | }) 64 | }) 65 | 66 | describe('when set to false', function() { 67 | beforeEach(function() { 68 | this.uploading = this.editor._uploading(false) 69 | }) 70 | 71 | it('returns false', function() { 72 | expect(this.uploading).to.be.false 73 | }) 74 | 75 | it('sets ._uploading', function() { 76 | expect(this.editor.__uploading).to.be.false 77 | }) 78 | 79 | it('adds the .uploading class', function() { 80 | expect(this.editor.$el).to.not.have.class('uploading') 81 | }) 82 | }) 83 | }) 84 | 85 | describe('.upload', function() { 86 | beforeEach(function() { 87 | this.xhr.prototype.upload = { addEventListener: sinon.stub() } 88 | }) 89 | 90 | it('opens the connection to the proper bucket', function() { 91 | this.xhr.prototype.open = sinon.stub() 92 | this.xhr.prototype.send = sinon.stub() 93 | this.config.s3_bucket = 'bucket' 94 | xhr = this.editor.upload(sinon.stub(), function() {}) 95 | expect(xhr.open).to.have.been.calledWith('POST', 'https://bucket.s3.amazonaws.com', true) 96 | }) 97 | 98 | it('sends the request', function() { 99 | this.xhr.prototype.send = sinon.stub() 100 | xhr = this.editor.upload(sinon.stub(), function() {}) 101 | expect(xhr.send).to.have.been.called 102 | }) 103 | 104 | describe('when the upload succeeds', function() { 105 | it('calls the callback with the location', function(done) { 106 | this.xhr.prototype.open = sinon.stub() 107 | this.xhr.prototype.send = sinon.stub() 108 | this.config.s3_bucket = 'bucket' 109 | xhr = this.editor.upload(sinon.stub(), function(location) { 110 | expect(location).to.eq('foo') 111 | done() 112 | }) 113 | xhr.getResponseHeader = sinon.stub().returns('foo') 114 | xhr.readyState = 4 115 | xhr.status = 204 116 | xhr.onreadystatechange() 117 | }) 118 | }) 119 | 120 | describe('when the upload fails', function() { 121 | it('shows an alert', function() { 122 | this.xhr.prototype.open = sinon.stub() 123 | this.xhr.prototype.send = sinon.stub() 124 | this.config.s3_bucket = 'bucket' 125 | alert = sinon.stub() 126 | xhr = this.editor.upload(sinon.stub(), function() {}) 127 | xhr.readyState = 4 128 | xhr.status = 403 129 | xhr.onreadystatechange() 130 | expect(alert).to.have.been.calledWith('Failed to upload file. Have you configured S3 properly?') 131 | }) 132 | }) 133 | 134 | describe('form data', function() { 135 | beforeEach(function() { 136 | file = this.file = { name: 'foobar', type: 'image/jpg' } 137 | append = this.append = sinon.stub() 138 | FormData = function() { return { append: append } } 139 | 140 | Date.now = function() { return { toString: function() { return '1234' } } } 141 | 142 | this.xhr.prototype.open = sinon.stub() 143 | this.xhr.prototype.send = sinon.stub() 144 | 145 | this.config.s3_bucket = 'bucket' 146 | this.config.storage_dir = 'uploads' 147 | this.config.aws_access_key_id = 'access key' 148 | 149 | this.editor.upload(file, function() {}) 150 | }) 151 | 152 | it('sets "key"', function() { 153 | expect(this.append).to.have.been.calledWith('key', 'uploads/1234-foobar') 154 | }) 155 | 156 | it('sets "AWSAccessKeyId"', function() { 157 | expect(this.append).to.have.been.calledWith('AWSAccessKeyId', 'access key') 158 | }) 159 | 160 | it('sets "acl"', function() { 161 | expect(this.append).to.have.been.calledWith('acl', 'public-read') 162 | }) 163 | 164 | it('sets "policy"', function() { 165 | expect(this.append).to.have.been.calledWith('policy', 'policy document') 166 | }) 167 | 168 | it('sets "signature"', function() { 169 | expect(this.append).to.have.been.calledWith('signature', 'policy signature') 170 | }) 171 | 172 | it('sets "Content-Type"', function() { 173 | expect(this.append).to.have.been.calledWith('Content-Type', 'image/jpg') 174 | }) 175 | 176 | it('sets "file"', function() { 177 | expect(this.append).to.have.been.calledWith('file', this.file) 178 | }) 179 | }) 180 | }) 181 | }) 182 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | active_admin_editor (1.1.0) 5 | activeadmin (>= 0.4.0) 6 | ejs 7 | rails (>= 3.0.0) 8 | 9 | GEM 10 | remote: http://rubygems.org/ 11 | specs: 12 | actionmailer (3.2.9) 13 | actionpack (= 3.2.9) 14 | mail (~> 2.4.4) 15 | actionpack (3.2.9) 16 | activemodel (= 3.2.9) 17 | activesupport (= 3.2.9) 18 | builder (~> 3.0.0) 19 | erubis (~> 2.7.0) 20 | journey (~> 1.0.4) 21 | rack (~> 1.4.0) 22 | rack-cache (~> 1.2) 23 | rack-test (~> 0.6.1) 24 | sprockets (~> 2.2.1) 25 | activeadmin (0.5.1) 26 | arbre (>= 1.0.1) 27 | bourbon (>= 1.0.0) 28 | devise (>= 1.1.2) 29 | fastercsv 30 | formtastic (>= 2.0.0) 31 | inherited_resources (>= 1.3.1) 32 | jquery-rails (>= 1.0.0) 33 | kaminari (>= 0.13.0) 34 | meta_search (>= 0.9.2) 35 | rails (>= 3.0.0) 36 | sass (>= 3.1.0) 37 | activemodel (3.2.9) 38 | activesupport (= 3.2.9) 39 | builder (~> 3.0.0) 40 | activerecord (3.2.9) 41 | activemodel (= 3.2.9) 42 | activesupport (= 3.2.9) 43 | arel (~> 3.0.2) 44 | tzinfo (~> 0.3.29) 45 | activeresource (3.2.9) 46 | activemodel (= 3.2.9) 47 | activesupport (= 3.2.9) 48 | activesupport (3.2.9) 49 | i18n (~> 0.6) 50 | multi_json (~> 1.0) 51 | arbre (1.0.1) 52 | activesupport (>= 3.0.0) 53 | arel (3.0.2) 54 | bcrypt-ruby (3.0.1) 55 | bourbon (3.0.1) 56 | sass (>= 3.2.0) 57 | thor 58 | builder (3.0.4) 59 | capybara (1.1.4) 60 | mime-types (>= 1.16) 61 | nokogiri (>= 1.3.3) 62 | rack (>= 1.0.0) 63 | rack-test (>= 0.5.4) 64 | selenium-webdriver (~> 2.0) 65 | xpath (~> 0.1.4) 66 | chai-jquery-rails (0.0.3) 67 | railties (~> 3.1) 68 | sprockets 69 | childprocess (0.3.9) 70 | ffi (~> 1.0, >= 1.0.11) 71 | coffee-rails (3.2.2) 72 | coffee-script (>= 2.2.0) 73 | railties (~> 3.2.0) 74 | coffee-script (2.2.0) 75 | coffee-script-source 76 | execjs 77 | coffee-script-source (1.4.0) 78 | colorize (0.5.8) 79 | database_cleaner (0.9.1) 80 | devise (2.1.2) 81 | bcrypt-ruby (~> 3.0) 82 | orm_adapter (~> 0.1) 83 | railties (~> 3.1) 84 | warden (~> 1.2.1) 85 | diff-lcs (1.1.3) 86 | ejs (1.1.1) 87 | erubis (2.7.0) 88 | eventmachine (1.0.0) 89 | execjs (1.4.0) 90 | multi_json (~> 1.0) 91 | factory_girl (4.1.0) 92 | activesupport (>= 3.0.0) 93 | factory_girl_rails (4.1.0) 94 | factory_girl (~> 4.1.0) 95 | railties (>= 3.0.0) 96 | faker (1.1.2) 97 | i18n (~> 0.5) 98 | fastercsv (1.5.5) 99 | faye-websocket (0.4.6) 100 | eventmachine (>= 0.12.0) 101 | ffi (1.9.0) 102 | formtastic (2.2.1) 103 | actionpack (>= 3.0) 104 | has_scope (0.5.1) 105 | hike (1.2.1) 106 | http_parser.rb (0.5.3) 107 | i18n (0.6.1) 108 | inherited_resources (1.3.1) 109 | has_scope (~> 0.5.0) 110 | responders (~> 0.6) 111 | journey (1.0.4) 112 | jquery-rails (2.1.4) 113 | railties (>= 3.0, < 5.0) 114 | thor (>= 0.14, < 2.0) 115 | json (1.7.6) 116 | kaminari (0.14.1) 117 | actionpack (>= 3.0.0) 118 | activesupport (>= 3.0.0) 119 | konacha (2.1.0) 120 | actionpack (~> 3.1) 121 | capybara 122 | colorize 123 | railties (~> 3.1) 124 | sprockets 125 | mail (2.4.4) 126 | i18n (>= 0.4.0) 127 | mime-types (~> 1.16) 128 | treetop (~> 1.4.8) 129 | meta_search (1.1.3) 130 | actionpack (~> 3.1) 131 | activerecord (~> 3.1) 132 | activesupport (~> 3.1) 133 | polyamorous (~> 0.5.0) 134 | mime-types (1.19) 135 | multi_json (1.7.7) 136 | nokogiri (1.5.6) 137 | orm_adapter (0.4.0) 138 | poltergeist (1.0.2) 139 | capybara (~> 1.1) 140 | childprocess (~> 0.3) 141 | faye-websocket (~> 0.4, >= 0.4.4) 142 | http_parser.rb (~> 0.5.3) 143 | multi_json (~> 1.0) 144 | polyamorous (0.5.0) 145 | activerecord (~> 3.0) 146 | polyglot (0.3.3) 147 | rack (1.4.1) 148 | rack-cache (1.2) 149 | rack (>= 0.4) 150 | rack-ssl (1.3.2) 151 | rack 152 | rack-test (0.6.2) 153 | rack (>= 1.0) 154 | rails (3.2.9) 155 | actionmailer (= 3.2.9) 156 | actionpack (= 3.2.9) 157 | activerecord (= 3.2.9) 158 | activeresource (= 3.2.9) 159 | activesupport (= 3.2.9) 160 | bundler (~> 1.0) 161 | railties (= 3.2.9) 162 | railties (3.2.9) 163 | actionpack (= 3.2.9) 164 | activesupport (= 3.2.9) 165 | rack-ssl (~> 1.3.2) 166 | rake (>= 0.8.7) 167 | rdoc (~> 3.4) 168 | thor (>= 0.14.6, < 2.0) 169 | rake (10.0.3) 170 | rdoc (3.12) 171 | json (~> 1.4) 172 | responders (0.9.3) 173 | railties (~> 3.1) 174 | rspec (2.12.0) 175 | rspec-core (~> 2.12.0) 176 | rspec-expectations (~> 2.12.0) 177 | rspec-mocks (~> 2.12.0) 178 | rspec-core (2.12.2) 179 | rspec-expectations (2.12.1) 180 | diff-lcs (~> 1.1.3) 181 | rspec-mocks (2.12.1) 182 | rspec-rails (2.12.0) 183 | actionpack (>= 3.0) 184 | activesupport (>= 3.0) 185 | railties (>= 3.0) 186 | rspec-core (~> 2.12.0) 187 | rspec-expectations (~> 2.12.0) 188 | rspec-mocks (~> 2.12.0) 189 | rubyzip (0.9.9) 190 | sass (3.2.4) 191 | sass-rails (3.2.5) 192 | railties (~> 3.2.0) 193 | sass (>= 3.1.10) 194 | tilt (~> 1.3) 195 | selenium-webdriver (2.33.0) 196 | childprocess (>= 0.2.5) 197 | multi_json (~> 1.0) 198 | rubyzip 199 | websocket (~> 1.0.4) 200 | sinon-chai-rails (1.0.2) 201 | railties (>= 3.1) 202 | sinon-rails (1.4.2.1) 203 | railties (>= 3.1) 204 | sprockets (2.2.2) 205 | hike (~> 1.2) 206 | multi_json (~> 1.0) 207 | rack (~> 1.0) 208 | tilt (~> 1.1, != 1.3.0) 209 | sqlite3 (1.3.6) 210 | thor (0.16.0) 211 | tilt (1.3.3) 212 | treetop (1.4.12) 213 | polyglot 214 | polyglot (>= 0.3.1) 215 | tzinfo (0.3.35) 216 | uglifier (1.3.0) 217 | execjs (>= 0.3.0) 218 | multi_json (~> 1.0, >= 1.0.2) 219 | warden (1.2.1) 220 | rack (>= 1.0) 221 | websocket (1.0.7) 222 | xpath (0.1.4) 223 | nokogiri (~> 1.3) 224 | 225 | PLATFORMS 226 | ruby 227 | 228 | DEPENDENCIES 229 | active_admin_editor! 230 | activeadmin 231 | capybara (~> 1.1.4) 232 | chai-jquery-rails 233 | coffee-rails 234 | database_cleaner (~> 0.9.1) 235 | ejs 236 | factory_girl_rails 237 | faker 238 | jquery-rails 239 | konacha 240 | meta_search 241 | poltergeist (~> 1.0.2) 242 | rspec (~> 2.12.0) 243 | rspec-rails (~> 2.12.0) 244 | sass-rails 245 | sinon-chai-rails 246 | sinon-rails 247 | sqlite3 248 | uglifier 249 | -------------------------------------------------------------------------------- /spec/dummy/README.rdoc: -------------------------------------------------------------------------------- 1 | == Welcome to Rails 2 | 3 | Rails is a web-application framework that includes everything needed to create 4 | database-backed web applications according to the Model-View-Control pattern. 5 | 6 | This pattern splits the view (also called the presentation) into "dumb" 7 | templates that are primarily responsible for inserting pre-built data in between 8 | HTML tags. The model contains the "smart" domain objects (such as Account, 9 | Product, Person, Post) that holds all the business logic and knows how to 10 | persist themselves to a database. The controller handles the incoming requests 11 | (such as Save New Account, Update Product, Show Post) by manipulating the model 12 | and directing data to the view. 13 | 14 | In Rails, the model is handled by what's called an object-relational mapping 15 | layer entitled Active Record. This layer allows you to present the data from 16 | database rows as objects and embellish these data objects with business logic 17 | methods. You can read more about Active Record in 18 | link:files/vendor/rails/activerecord/README.html. 19 | 20 | The controller and view are handled by the Action Pack, which handles both 21 | layers by its two parts: Action View and Action Controller. These two layers 22 | are bundled in a single package due to their heavy interdependence. This is 23 | unlike the relationship between the Active Record and Action Pack that is much 24 | more separate. Each of these packages can be used independently outside of 25 | Rails. You can read more about Action Pack in 26 | link:files/vendor/rails/actionpack/README.html. 27 | 28 | 29 | == Getting Started 30 | 31 | 1. At the command prompt, create a new Rails application: 32 | rails new myapp (where myapp is the application name) 33 | 34 | 2. Change directory to myapp and start the web server: 35 | cd myapp; rails server (run with --help for options) 36 | 37 | 3. Go to http://localhost:3000/ and you'll see: 38 | "Welcome aboard: You're riding Ruby on Rails!" 39 | 40 | 4. Follow the guidelines to start developing your application. You can find 41 | the following resources handy: 42 | 43 | * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html 44 | * Ruby on Rails Tutorial Book: http://www.railstutorial.org/ 45 | 46 | 47 | == Debugging Rails 48 | 49 | Sometimes your application goes wrong. Fortunately there are a lot of tools that 50 | will help you debug it and get it back on the rails. 51 | 52 | First area to check is the application log files. Have "tail -f" commands 53 | running on the server.log and development.log. Rails will automatically display 54 | debugging and runtime information to these files. Debugging info will also be 55 | shown in the browser on requests from 127.0.0.1. 56 | 57 | You can also log your own messages directly into the log file from your code 58 | using the Ruby logger class from inside your controllers. Example: 59 | 60 | class WeblogController < ActionController::Base 61 | def destroy 62 | @weblog = Weblog.find(params[:id]) 63 | @weblog.destroy 64 | logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") 65 | end 66 | end 67 | 68 | The result will be a message in your log file along the lines of: 69 | 70 | Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1! 71 | 72 | More information on how to use the logger is at http://www.ruby-doc.org/core/ 73 | 74 | Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are 75 | several books available online as well: 76 | 77 | * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe) 78 | * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) 79 | 80 | These two books will bring you up to speed on the Ruby language and also on 81 | programming in general. 82 | 83 | 84 | == Debugger 85 | 86 | Debugger support is available through the debugger command when you start your 87 | Mongrel or WEBrick server with --debugger. This means that you can break out of 88 | execution at any point in the code, investigate and change the model, and then, 89 | resume execution! You need to install ruby-debug to run the server in debugging 90 | mode. With gems, use sudo gem install ruby-debug. Example: 91 | 92 | class WeblogController < ActionController::Base 93 | def index 94 | @posts = Post.all 95 | debugger 96 | end 97 | end 98 | 99 | So the controller will accept the action, run the first line, then present you 100 | with a IRB prompt in the server window. Here you can do things like: 101 | 102 | >> @posts.inspect 103 | => "[#nil, "body"=>nil, "id"=>"1"}>, 105 | #"Rails", "body"=>"Only ten..", "id"=>"2"}>]" 107 | >> @posts.first.title = "hello from a debugger" 108 | => "hello from a debugger" 109 | 110 | ...and even better, you can examine how your runtime objects actually work: 111 | 112 | >> f = @posts.first 113 | => #nil, "body"=>nil, "id"=>"1"}> 114 | >> f. 115 | Display all 152 possibilities? (y or n) 116 | 117 | Finally, when you're ready to resume execution, you can enter "cont". 118 | 119 | 120 | == Console 121 | 122 | The console is a Ruby shell, which allows you to interact with your 123 | application's domain model. Here you'll have all parts of the application 124 | configured, just like it is when the application is running. You can inspect 125 | domain models, change values, and save to the database. Starting the script 126 | without arguments will launch it in the development environment. 127 | 128 | To start the console, run rails console from the application 129 | directory. 130 | 131 | Options: 132 | 133 | * Passing the -s, --sandbox argument will rollback any modifications 134 | made to the database. 135 | * Passing an environment name as an argument will load the corresponding 136 | environment. Example: rails console production. 137 | 138 | To reload your controllers and models after launching the console run 139 | reload! 140 | 141 | More information about irb can be found at: 142 | link:http://www.rubycentral.org/pickaxe/irb.html 143 | 144 | 145 | == dbconsole 146 | 147 | You can go to the command line of your database directly through rails 148 | dbconsole. You would be connected to the database with the credentials 149 | defined in database.yml. Starting the script without arguments will connect you 150 | to the development database. Passing an argument will connect you to a different 151 | database, like rails dbconsole production. Currently works for MySQL, 152 | PostgreSQL and SQLite 3. 153 | 154 | == Description of Contents 155 | 156 | The default directory structure of a generated Ruby on Rails application: 157 | 158 | |-- app 159 | | |-- assets 160 | | |-- images 161 | | |-- javascripts 162 | | `-- stylesheets 163 | | |-- controllers 164 | | |-- helpers 165 | | |-- mailers 166 | | |-- models 167 | | `-- views 168 | | `-- layouts 169 | |-- config 170 | | |-- environments 171 | | |-- initializers 172 | | `-- locales 173 | |-- db 174 | |-- doc 175 | |-- lib 176 | | `-- tasks 177 | |-- log 178 | |-- public 179 | |-- script 180 | |-- test 181 | | |-- fixtures 182 | | |-- functional 183 | | |-- integration 184 | | |-- performance 185 | | `-- unit 186 | |-- tmp 187 | | |-- cache 188 | | |-- pids 189 | | |-- sessions 190 | | `-- sockets 191 | `-- vendor 192 | |-- assets 193 | `-- stylesheets 194 | `-- plugins 195 | 196 | app 197 | Holds all the code that's specific to this particular application. 198 | 199 | app/assets 200 | Contains subdirectories for images, stylesheets, and JavaScript files. 201 | 202 | app/controllers 203 | Holds controllers that should be named like weblogs_controller.rb for 204 | automated URL mapping. All controllers should descend from 205 | ApplicationController which itself descends from ActionController::Base. 206 | 207 | app/models 208 | Holds models that should be named like post.rb. Models descend from 209 | ActiveRecord::Base by default. 210 | 211 | app/views 212 | Holds the template files for the view that should be named like 213 | weblogs/index.html.erb for the WeblogsController#index action. All views use 214 | eRuby syntax by default. 215 | 216 | app/views/layouts 217 | Holds the template files for layouts to be used with views. This models the 218 | common header/footer method of wrapping views. In your views, define a layout 219 | using the layout :default and create a file named default.html.erb. 220 | Inside default.html.erb, call <% yield %> to render the view using this 221 | layout. 222 | 223 | app/helpers 224 | Holds view helpers that should be named like weblogs_helper.rb. These are 225 | generated for you automatically when using generators for controllers. 226 | Helpers can be used to wrap functionality for your views into methods. 227 | 228 | config 229 | Configuration files for the Rails environment, the routing map, the database, 230 | and other dependencies. 231 | 232 | db 233 | Contains the database schema in schema.rb. db/migrate contains all the 234 | sequence of Migrations for your schema. 235 | 236 | doc 237 | This directory is where your application documentation will be stored when 238 | generated using rake doc:app 239 | 240 | lib 241 | Application specific libraries. Basically, any kind of custom code that 242 | doesn't belong under controllers, models, or helpers. This directory is in 243 | the load path. 244 | 245 | public 246 | The directory available for the web server. Also contains the dispatchers and the 247 | default HTML files. This should be set as the DOCUMENT_ROOT of your web 248 | server. 249 | 250 | script 251 | Helper scripts for automation and generation. 252 | 253 | test 254 | Unit and functional tests along with fixtures. When using the rails generate 255 | command, template test files will be generated for you and placed in this 256 | directory. 257 | 258 | vendor 259 | External libraries that the application depends on. Also includes the plugins 260 | subdirectory. If the app has frozen rails, those gems also go here, under 261 | vendor/rails/. This directory is in the load path. 262 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # Use this hook to configure devise mailer, warden hooks and so forth. 2 | # Many of these configuration options can be set straight in your model. 3 | Devise.setup do |config| 4 | # ==> Mailer Configuration 5 | # Configure the e-mail address which will be shown in Devise::Mailer, 6 | # note that it will be overwritten if you use your own mailer class with default "from" parameter. 7 | config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" 8 | 9 | # Configure the class responsible to send e-mails. 10 | # config.mailer = "Devise::Mailer" 11 | 12 | # ==> ORM configuration 13 | # Load and configure the ORM. Supports :active_record (default) and 14 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 15 | # available as additional gems. 16 | require 'devise/orm/active_record' 17 | 18 | # ==> Configuration for any authentication mechanism 19 | # Configure which keys are used when authenticating a user. The default is 20 | # just :email. You can configure it to use [:username, :subdomain], so for 21 | # authenticating a user, both parameters are required. Remember that those 22 | # parameters are used only when authenticating and not when retrieving from 23 | # session. If you need permissions, you should implement that in a before filter. 24 | # You can also supply a hash where the value is a boolean determining whether 25 | # or not authentication should be aborted when the value is not present. 26 | # config.authentication_keys = [ :email ] 27 | 28 | # Configure parameters from the request object used for authentication. Each entry 29 | # given should be a request method and it will automatically be passed to the 30 | # find_for_authentication method and considered in your model lookup. For instance, 31 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 32 | # The same considerations mentioned for authentication_keys also apply to request_keys. 33 | # config.request_keys = [] 34 | 35 | # Configure which authentication keys should be case-insensitive. 36 | # These keys will be downcased upon creating or modifying a user and when used 37 | # to authenticate or find a user. Default is :email. 38 | config.case_insensitive_keys = [ :email ] 39 | 40 | # Configure which authentication keys should have whitespace stripped. 41 | # These keys will have whitespace before and after removed upon creating or 42 | # modifying a user and when used to authenticate or find a user. Default is :email. 43 | config.strip_whitespace_keys = [ :email ] 44 | 45 | # Tell if authentication through request.params is enabled. True by default. 46 | # It can be set to an array that will enable params authentication only for the 47 | # given strategies, for example, `config.params_authenticatable = [:database]` will 48 | # enable it only for database (email + password) authentication. 49 | # config.params_authenticatable = true 50 | 51 | # Tell if authentication through HTTP Basic Auth is enabled. False by default. 52 | # It can be set to an array that will enable http authentication only for the 53 | # given strategies, for example, `config.http_authenticatable = [:token]` will 54 | # enable it only for token authentication. 55 | # config.http_authenticatable = false 56 | 57 | # If http headers should be returned for AJAX requests. True by default. 58 | # config.http_authenticatable_on_xhr = true 59 | 60 | # The realm used in Http Basic Authentication. "Application" by default. 61 | # config.http_authentication_realm = "Application" 62 | 63 | # It will change confirmation, password recovery and other workflows 64 | # to behave the same regardless if the e-mail provided was right or wrong. 65 | # Does not affect registerable. 66 | # config.paranoid = true 67 | 68 | # By default Devise will store the user in session. You can skip storage for 69 | # :http_auth and :token_auth by adding those symbols to the array below. 70 | # Notice that if you are skipping storage for all authentication paths, you 71 | # may want to disable generating routes to Devise's sessions controller by 72 | # passing :skip => :sessions to `devise_for` in your config/routes.rb 73 | config.skip_session_storage = [:http_auth] 74 | 75 | # ==> Configuration for :database_authenticatable 76 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If 77 | # using other encryptors, it sets how many times you want the password re-encrypted. 78 | # 79 | # Limiting the stretches to just one in testing will increase the performance of 80 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 81 | # a value less than 10 in other environments. 82 | config.stretches = Rails.env.test? ? 1 : 10 83 | 84 | # Setup a pepper to generate the encrypted password. 85 | # config.pepper = "5e3c9f8d9beca0072c4b0099be80b8509062915d1f41d5f7b7116b8da5251d8fe513329891f916f1d6ddb460a64bb77d9afd1dfe1dcb0757e6c4575c8f7d05b8" 86 | 87 | # ==> Configuration for :confirmable 88 | # A period that the user is allowed to access the website even without 89 | # confirming his account. For instance, if set to 2.days, the user will be 90 | # able to access the website for two days without confirming his account, 91 | # access will be blocked just in the third day. Default is 0.days, meaning 92 | # the user cannot access the website without confirming his account. 93 | # config.allow_unconfirmed_access_for = 2.days 94 | 95 | # If true, requires any email changes to be confirmed (exctly the same way as 96 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 97 | # db field (see migrations). Until confirmed new email is stored in 98 | # unconfirmed email column, and copied to email column on successful confirmation. 99 | config.reconfirmable = true 100 | 101 | # Defines which key will be used when confirming an account 102 | # config.confirmation_keys = [ :email ] 103 | 104 | # ==> Configuration for :rememberable 105 | # The time the user will be remembered without asking for credentials again. 106 | # config.remember_for = 2.weeks 107 | 108 | # If true, extends the user's remember period when remembered via cookie. 109 | # config.extend_remember_period = false 110 | 111 | # Options to be passed to the created cookie. For instance, you can set 112 | # :secure => true in order to force SSL only cookies. 113 | # config.cookie_options = {} 114 | 115 | # ==> Configuration for :validatable 116 | # Range for password length. Default is 6..128. 117 | # config.password_length = 6..128 118 | 119 | # Email regex used to validate email formats. It simply asserts that 120 | # an one (and only one) @ exists in the given string. This is mainly 121 | # to give user feedback and not to assert the e-mail validity. 122 | # config.email_regexp = /\A[^@]+@[^@]+\z/ 123 | 124 | # ==> Configuration for :timeoutable 125 | # The time you want to timeout the user session without activity. After this 126 | # time the user will be asked for credentials again. Default is 30 minutes. 127 | # config.timeout_in = 30.minutes 128 | 129 | # ==> Configuration for :lockable 130 | # Defines which strategy will be used to lock an account. 131 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 132 | # :none = No lock strategy. You should handle locking by yourself. 133 | # config.lock_strategy = :failed_attempts 134 | 135 | # Defines which key will be used when locking and unlocking an account 136 | # config.unlock_keys = [ :email ] 137 | 138 | # Defines which strategy will be used to unlock an account. 139 | # :email = Sends an unlock link to the user email 140 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 141 | # :both = Enables both strategies 142 | # :none = No unlock strategy. You should handle unlocking by yourself. 143 | # config.unlock_strategy = :both 144 | 145 | # Number of authentication tries before locking an account if lock_strategy 146 | # is failed attempts. 147 | # config.maximum_attempts = 20 148 | 149 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 150 | # config.unlock_in = 1.hour 151 | 152 | # ==> Configuration for :recoverable 153 | # 154 | # Defines which key will be used when recovering the password for an account 155 | # config.reset_password_keys = [ :email ] 156 | 157 | # Time interval you can reset your password with a reset password key. 158 | # Don't put a too small interval or your users won't have the time to 159 | # change their passwords. 160 | config.reset_password_within = 6.hours 161 | 162 | # ==> Configuration for :encryptable 163 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use 164 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, 165 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) 166 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy 167 | # REST_AUTH_SITE_KEY to pepper) 168 | # config.encryptor = :sha512 169 | 170 | # ==> Configuration for :token_authenticatable 171 | # Defines name of the authentication token params key 172 | # config.token_authentication_key = :auth_token 173 | 174 | # ==> Scopes configuration 175 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 176 | # "users/sessions/new". It's turned off by default because it's slower if you 177 | # are using only default views. 178 | # config.scoped_views = false 179 | 180 | # Configure the default scope given to Warden. By default it's the first 181 | # devise role declared in your routes (usually :user). 182 | # config.default_scope = :user 183 | 184 | # Configure sign_out behavior. 185 | # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope). 186 | # The default is true, which means any logout action will sign out all active scopes. 187 | # config.sign_out_all_scopes = true 188 | 189 | # ==> Navigation configuration 190 | # Lists the formats that should be treated as navigational. Formats like 191 | # :html, should redirect to the sign in page when the user does not have 192 | # access, but formats like :xml or :json, should return 401. 193 | # 194 | # If you have any extra navigational formats, like :iphone or :mobile, you 195 | # should add them to the navigational formats lists. 196 | # 197 | # The "*/*" below is required to match Internet Explorer requests. 198 | # config.navigational_formats = ["*/*", :html] 199 | 200 | # The default HTTP method used to sign out a resource. Default is :delete. 201 | config.sign_out_via = :delete 202 | 203 | # ==> OmniAuth 204 | # Add a new OmniAuth provider. Check the wiki for more information on setting 205 | # up on your models and hooks. 206 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' 207 | 208 | # ==> Warden configuration 209 | # If you want to use other strategies, that are not supported by Devise, or 210 | # change the failure app, you can configure them inside the config.warden block. 211 | # 212 | # config.warden do |manager| 213 | # manager.intercept_401 = false 214 | # manager.default_strategies(:scope => :user).unshift :some_external_strategy 215 | # end 216 | end 217 | -------------------------------------------------------------------------------- /lib/active_admin/editor/parser_rules.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Editor 3 | # Full HTML5 compatibility rule set 4 | # These rules define which tags and CSS classes are supported and which tags should be specially treated. 5 | # 6 | # Examples based on this rule set: 7 | # 8 | # foo 9 | # ... becomes ... 10 | # foo 11 | # 12 | # 13 | # ... becomes ... 14 | # 15 | # 16 | #
    foo
    17 | # ... becomes ... 18 | #
    foo
    19 | # 20 | # foo 21 | # ... becomes ... 22 | # foo 23 | # 24 | # foo
    bar 25 | # ... becomes ... 26 | # foo
    bar 27 | # 28 | #
    hello
    29 | # ... becomes ... 30 | #
    hello
    31 | # 32 | #
    hello
    33 | # ... becomes ... 34 | #
    hello
    35 | PARSER_RULES = { 36 | # CSS Class white-list 37 | # Following CSS classes won't be removed when parsed by the wysihtml5 HTML parser 38 | 'classes' => { 39 | 'wysiwyg-clear-both' => 1, 40 | 'wysiwyg-clear-left' => 1, 41 | 'wysiwyg-clear-right' => 1, 42 | 'wysiwyg-color-aqua' => 1, 43 | 'wysiwyg-color-black' => 1, 44 | 'wysiwyg-color-blue' => 1, 45 | 'wysiwyg-color-fuchsia' => 1, 46 | 'wysiwyg-color-gray' => 1, 47 | 'wysiwyg-color-green' => 1, 48 | 'wysiwyg-color-lime' => 1, 49 | 'wysiwyg-color-maroon' => 1, 50 | 'wysiwyg-color-navy' => 1, 51 | 'wysiwyg-color-olive' => 1, 52 | 'wysiwyg-color-purple' => 1, 53 | 'wysiwyg-color-red' => 1, 54 | 'wysiwyg-color-silver' => 1, 55 | 'wysiwyg-color-teal' => 1, 56 | 'wysiwyg-color-white' => 1, 57 | 'wysiwyg-color-yellow' => 1, 58 | 'wysiwyg-float-left' => 1, 59 | 'wysiwyg-float-right' => 1, 60 | 'wysiwyg-font-size-large' => 1, 61 | 'wysiwyg-font-size-larger' => 1, 62 | 'wysiwyg-font-size-medium' => 1, 63 | 'wysiwyg-font-size-small' => 1, 64 | 'wysiwyg-font-size-smaller' => 1, 65 | 'wysiwyg-font-size-x-large' => 1, 66 | 'wysiwyg-font-size-x-small' => 1, 67 | 'wysiwyg-font-size-xx-large' => 1, 68 | 'wysiwyg-font-size-xx-small' => 1, 69 | 'wysiwyg-text-align-center' => 1, 70 | 'wysiwyg-text-align-justify' => 1, 71 | 'wysiwyg-text-align-left' => 1, 72 | 'wysiwyg-text-align-right' => 1 73 | }, 74 | # Tag list 75 | # 76 | # The following options are available: 77 | # 78 | # - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class 79 | # The following methods are implemented in wysihtml5.dom.parse: 80 | # - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*") 81 | #

    foo

    ... becomes ...

    class="wysiwyg-text-align-center">foo

    82 | # - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*" 83 | #
    ... becomes ...
    84 | # - align_img: converts align attribute values (right/left) on to their corresponding css class "wysiwyg-float-*" 85 | # 86 | # - remove: removes the element and its content 87 | # 88 | # - rename_tag: renames the element to the given tag 89 | # 90 | # - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above) 91 | # 92 | # - set_attributes: sets/overrides the given attributes 93 | # 94 | # - check_attributes: checks the given HTML attribute via the given method 95 | # - url: allows only valid urls (starting with http:// or https://) 96 | # - src: allows something like "/foobar.jpg", "http://google.com", ... 97 | # - href: allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg" 98 | # - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML) 99 | # - numbers: ensures that the attribute only contains numeric characters 100 | 'tags' => { 101 | 'tr' => { 102 | 'add_class' => { 103 | 'align' => 'align_text' 104 | } 105 | }, 106 | 'strike' => { 107 | 'remove' => 1 108 | }, 109 | 'form' => { 110 | 'rename_tag' => 'div' 111 | }, 112 | 'rt' => { 113 | 'rename_tag' => 'span' 114 | }, 115 | 'code' => {}, 116 | 'acronym' => { 117 | 'rename_tag' => 'span' 118 | }, 119 | 'br' => { 120 | 'add_class' => { 121 | 'clear' => 'clear_br' 122 | } 123 | }, 124 | 'details' => { 125 | 'rename_tag' => 'div' 126 | }, 127 | 'h4' => { 128 | 'add_class' => { 129 | 'align' => 'align_text' 130 | } 131 | }, 132 | 'em' => {}, 133 | 'title' => { 134 | 'remove' => 1 135 | }, 136 | 'multicol' => { 137 | 'rename_tag' => 'div' 138 | }, 139 | 'figure' => { 140 | 'rename_tag' => 'div' 141 | }, 142 | 'xmp' => { 143 | 'rename_tag' => 'span' 144 | }, 145 | 'small' => { 146 | 'rename_tag' => 'span', 147 | 'set_class' => 'wysiwyg-font-size-smaller' 148 | }, 149 | 'area' => { 150 | 'remove' => 1 151 | }, 152 | 'time' => { 153 | 'rename_tag' => 'span' 154 | }, 155 | 'dir' => { 156 | 'rename_tag' => 'ul' 157 | }, 158 | 'bdi' => { 159 | 'rename_tag' => 'span' 160 | }, 161 | 'command' => { 162 | 'remove' => 1 163 | }, 164 | 'ul' => {}, 165 | 'progress' => { 166 | 'rename_tag' => 'span' 167 | }, 168 | 'dfn' => { 169 | 'rename_tag' => 'span' 170 | }, 171 | 'iframe' => { 172 | 'remove' => 1 173 | }, 174 | 'figcaption' => { 175 | 'rename_tag' => 'div' 176 | }, 177 | 'a' => { 178 | 'check_attributes' => { 179 | 'href' => 'url' # if you compiled master manually then change this from 'url' to 'href' 180 | }, 181 | 'set_attributes' => { 182 | 'target' => '_blank' 183 | } 184 | }, 185 | 'img' => { 186 | 'check_attributes' => { 187 | 'width' => 'numbers', 188 | 'alt' => 'alt', 189 | 'src' => 'url', # if you compiled master manually then change this from 'url' to 'src' 190 | 'height' => 'numbers' 191 | }, 192 | 'add_class' => { 193 | 'align' => 'align_img' 194 | } 195 | }, 196 | 'rb' => { 197 | 'rename_tag' => 'span' 198 | }, 199 | 'footer' => { 200 | 'rename_tag' => 'div' 201 | }, 202 | 'noframes' => { 203 | 'remove' => 1 204 | }, 205 | 'abbr' => { 206 | 'rename_tag' => 'span' 207 | }, 208 | 'u' => {}, 209 | 'bgsound' => { 210 | 'remove' => 1 211 | }, 212 | 'sup' => { 213 | 'rename_tag' => 'span' 214 | }, 215 | 'address' => { 216 | 'rename_tag' => 'div' 217 | }, 218 | 'basefont' => { 219 | 'remove' => 1 220 | }, 221 | 'nav' => { 222 | 'rename_tag' => 'div' 223 | }, 224 | 'h1' => { 225 | 'add_class' => { 226 | 'align' => 'align_text' 227 | } 228 | }, 229 | 'head' => { 230 | 'remove' => 1 231 | }, 232 | 'tbody' => { 233 | 'add_class' => { 234 | 'align' => 'align_text' 235 | } 236 | }, 237 | 'dd' => { 238 | 'rename_tag' => 'div' 239 | }, 240 | 's' => { 241 | 'rename_tag' => 'span' 242 | }, 243 | 'li' => {}, 244 | 'td' => { 245 | 'check_attributes' => { 246 | 'rowspan' => 'numbers', 247 | 'colspan' => 'numbers' 248 | }, 249 | 'add_class' => { 250 | 'align' => 'align_text' 251 | } 252 | }, 253 | 'object' => { 254 | 'remove' => 1 255 | }, 256 | 'div' => { 257 | 'add_class' => { 258 | 'align' => 'align_text' 259 | } 260 | }, 261 | 'option' => { 262 | 'rename_tag' => 'span' 263 | }, 264 | 'select' => { 265 | 'rename_tag' => 'span' 266 | }, 267 | 'i' => {}, 268 | 'track' => { 269 | 'remove' => 1 270 | }, 271 | 'wbr' => { 272 | 'remove' => 1 273 | }, 274 | 'fieldset' => { 275 | 'rename_tag' => 'div' 276 | }, 277 | 'big' => { 278 | 'rename_tag' => 'span', 279 | 'set_class' => 'wysiwyg-font-size-larger' 280 | }, 281 | 'button' => { 282 | 'rename_tag' => 'span' 283 | }, 284 | 'noscript' => { 285 | 'remove' => 1 286 | }, 287 | 'svg' => { 288 | 'remove' => 1 289 | }, 290 | 'input' => { 291 | 'remove' => 1 292 | }, 293 | 'table' => {}, 294 | 'keygen' => { 295 | 'remove' => 1 296 | }, 297 | 'h5' => { 298 | 'add_class' => { 299 | 'align' => 'align_text' 300 | } 301 | }, 302 | 'meta' => { 303 | 'remove' => 1 304 | }, 305 | 'map' => { 306 | 'rename_tag' => 'div' 307 | }, 308 | 'isindex' => { 309 | 'remove' => 1 310 | }, 311 | 'mark' => { 312 | 'rename_tag' => 'span' 313 | }, 314 | 'caption' => { 315 | 'add_class' => { 316 | 'align' => 'align_text' 317 | } 318 | }, 319 | 'tfoot' => { 320 | 'add_class' => { 321 | 'align' => 'align_text' 322 | } 323 | }, 324 | 'base' => { 325 | 'remove' => 1 326 | }, 327 | 'video' => { 328 | 'remove' => 1 329 | }, 330 | 'strong' => {}, 331 | 'canvas' => { 332 | 'remove' => 1 333 | }, 334 | 'output' => { 335 | 'rename_tag' => 'span' 336 | }, 337 | 'marquee' => { 338 | 'rename_tag' => 'span' 339 | }, 340 | 'b' => {}, 341 | 'q' => { 342 | 'check_attributes' => { 343 | 'cite' => 'url' 344 | } 345 | }, 346 | 'applet' => { 347 | 'remove' => 1 348 | }, 349 | 'span' => {}, 350 | 'rp' => { 351 | 'rename_tag' => 'span' 352 | }, 353 | 'spacer' => { 354 | 'remove' => 1 355 | }, 356 | 'source' => { 357 | 'remove' => 1 358 | }, 359 | 'aside' => { 360 | 'rename_tag' => 'div' 361 | }, 362 | 'frame' => { 363 | 'remove' => 1 364 | }, 365 | 'section' => { 366 | 'rename_tag' => 'div' 367 | }, 368 | 'body' => { 369 | 'rename_tag' => 'div' 370 | }, 371 | 'ol' => {}, 372 | 'nobr' => { 373 | 'rename_tag' => 'span' 374 | }, 375 | 'html' => { 376 | 'rename_tag' => 'div' 377 | }, 378 | 'summary' => { 379 | 'rename_tag' => 'span' 380 | }, 381 | 'var' => { 382 | 'rename_tag' => 'span' 383 | }, 384 | 'del' => { 385 | 'remove' => 1 386 | }, 387 | 'blockquote' => { 388 | 'check_attributes' => { 389 | 'cite' => 'url' 390 | } 391 | }, 392 | 'style' => { 393 | 'remove' => 1 394 | }, 395 | 'device' => { 396 | 'remove' => 1 397 | }, 398 | 'meter' => { 399 | 'rename_tag' => 'span' 400 | }, 401 | 'h3' => { 402 | 'add_class' => { 403 | 'align' => 'align_text' 404 | } 405 | }, 406 | 'textarea' => { 407 | 'rename_tag' => 'span' 408 | }, 409 | 'embed' => { 410 | 'remove' => 1 411 | }, 412 | 'hgroup' => { 413 | 'rename_tag' => 'div' 414 | }, 415 | 'font' => { 416 | 'rename_tag' => 'span', 417 | 'add_class' => { 418 | 'size' => 'size_font' 419 | } 420 | }, 421 | 'tt' => { 422 | 'rename_tag' => 'span' 423 | }, 424 | 'noembed' => { 425 | 'remove' => 1 426 | }, 427 | 'thead' => { 428 | 'add_class' => { 429 | 'align' => 'align_text' 430 | } 431 | }, 432 | 'blink' => { 433 | 'rename_tag' => 'span' 434 | }, 435 | 'plaintext' => { 436 | 'rename_tag' => 'span' 437 | }, 438 | 'xml' => { 439 | 'remove' => 1 440 | }, 441 | 'h6' => { 442 | 'add_class' => { 443 | 'align' => 'align_text' 444 | } 445 | }, 446 | 'param' => { 447 | 'remove' => 1 448 | }, 449 | 'th' => { 450 | 'check_attributes' => { 451 | 'rowspan' => 'numbers', 452 | 'colspan' => 'numbers' 453 | }, 454 | 'add_class' => { 455 | 'align' => 'align_text' 456 | } 457 | }, 458 | 'legend' => { 459 | 'rename_tag' => 'span' 460 | }, 461 | 'hr' => {}, 462 | 'label' => { 463 | 'rename_tag' => 'span' 464 | }, 465 | 'dl' => { 466 | 'rename_tag' => 'div' 467 | }, 468 | 'kbd' => { 469 | 'rename_tag' => 'span' 470 | }, 471 | 'listing' => { 472 | 'rename_tag' => 'div' 473 | }, 474 | 'dt' => { 475 | 'rename_tag' => 'span' 476 | }, 477 | 'nextid' => { 478 | 'remove' => 1 479 | }, 480 | 'pre' => {}, 481 | 'center' => { 482 | 'rename_tag' => 'div', 483 | 'set_class' => 'wysiwyg-text-align-center' 484 | }, 485 | 'audio' => { 486 | 'remove' => 1 487 | }, 488 | 'datalist' => { 489 | 'rename_tag' => 'span' 490 | }, 491 | 'samp' => { 492 | 'rename_tag' => 'span' 493 | }, 494 | 'col' => { 495 | 'remove' => 1 496 | }, 497 | 'article' => { 498 | 'rename_tag' => 'div' 499 | }, 500 | 'cite' => {}, 501 | 'link' => { 502 | 'remove' => 1 503 | }, 504 | 'script' => { 505 | 'remove' => 1 506 | }, 507 | 'bdo' => { 508 | 'rename_tag' => 'span' 509 | }, 510 | 'menu' => { 511 | 'rename_tag' => 'ul' 512 | }, 513 | 'colgroup' => { 514 | 'remove' => 1 515 | }, 516 | 'ruby' => { 517 | 'rename_tag' => 'span' 518 | }, 519 | 'h2' => { 520 | 'add_class' => { 521 | 'align' => 'align_text' 522 | } 523 | }, 524 | 'ins' => { 525 | 'rename_tag' => 'span' 526 | }, 527 | 'p' => { 528 | 'add_class' => { 529 | 'align' => 'align_text' 530 | } 531 | }, 532 | 'sub' => { 533 | 'rename_tag' => 'span' 534 | }, 535 | 'comment' => { 536 | 'remove' => 1 537 | }, 538 | 'frameset' => { 539 | 'remove' => 1 540 | }, 541 | 'optgroup' => { 542 | 'rename_tag' => 'span' 543 | }, 544 | 'header' => { 545 | 'rename_tag' => 'div' 546 | } 547 | } 548 | } 549 | end 550 | end 551 | --------------------------------------------------------------------------------