Permalink
Browse files

added mongoid model to the generator and updated readme/post install …

…info.
  • Loading branch information...
1 parent 4877c50 commit e7388894175a4eb9c5ca875f57bd6f078e2f191e @chandresh chandresh committed with jejacks0n Jan 11, 2012
View
@@ -4,12 +4,12 @@ and other useful info can be found at: https://github.com/jejacks0n/mercury
Here's a post install checklist:
-* Setup the database for image processing (if you haven't already) by running
+* Setup the database for image processing (ActiveRecord only) by running:
rake mercury_engine:install:migrations
rake db:migrate
-* Learn about, and make your configuration adjustments in the mercury.js file
+* Learn about, and make configuration adjustments in the mercury.js file.
* If installed, check out mercury.html.erb and mercury_overrides.css for more
customization info.
View
@@ -105,11 +105,15 @@ You can also get the configuration file, css, and routes by running the generato
rails generate mercury:install
This generator puts the mercury base file (configuration) into your project in /app/assets/javascripts/mercury.js,
-and includes the base mercury routes. It can optionally install the layout and a css overrides file, as well as an
-authentication helper that allows you to restrict access to editing.
+and includes the base mercury routes. It can optionally install the layout and a css overrides file, models, as well as
+an authentication helper that allows you to restrict access to editing. Check the options by using `--help`.
-Make sure you get the migrations that you'll need for image uploading (if not you can disable the feature in
-mercury.js).
+For Mongoid + MongoDB, you can use the `--orm=mongoid` option on the generator to get the required models added to your
+app. Make sure to add `gem "mongoid-paperclip", :require => "mongoid_paperclip` to your Gemfile as well. Thanks to
+[chandresh](https://github.com/chandresh) for this tip.
+
+If you're using ActiveRecord, make sure you get the migrations that you'll need for image uploading (if not you can
+disable the feature in mercury.js if you don't want it).
rake mercury_engine:install:migrations
rake db:migrate
@@ -141,7 +145,6 @@ include one. Region types are outlined below.
For more advanced ways to integrate Mercury Editor with your Rails application check out this
[wiki article](https://github.com/jejacks0n/mercury/wiki/Rails-Integration-Techniques).
-
### Using Mercury without Rails
Check this [wiki article](https://github.com/jejacks0n/mercury/wiki/Using-Mercury-without-Rails)
@@ -5,7 +5,10 @@ class InstallGenerator < Rails::Generators::Base
desc "Installs Mercury into your application by copying the configuration file."
- class_option :full, :type => :boolean, :aliases => "-f",
+ class_option :orm, :default => 'active_record', :banner => 'mongoid',
+ :desc => 'ORM for required models -- active_record, or mongoid'
+
+ class_option :full, :type => :boolean, :aliases => '-g',
:desc => 'Full installation will install the layout and css overrides for easier customization.'
def copy_config
@@ -16,6 +19,14 @@ def add_routes
route %Q{Mercury::Engine.routes}
end
+ def copy_models
+ if options[:orm] == 'mongoid'
+ copy_file 'lib/generators/mercury/install/templates/mongoid_paperclip_image.rb', 'app/models/mercury/image.rb'
+ else
+ copy_file 'app/models/mercury/image.rb' if options[:full]
+ end
+ end
+
def copy_layout_and_css_overrides
if options[:full] || yes?("Install the layout and CSS overrides files? [yN]")
copy_file 'app/views/layouts/mercury.html.erb', 'app/views/layouts/mercury.html.erb'
@@ -30,7 +41,7 @@ def copy_authentication_overrides
end
def display_readme
- readme 'POST_INSTALL'
+ readme 'POST_INSTALL' if behavior == :invoke
end
end
@@ -0,0 +1,17 @@
+class Mercury::Image
+ include Mongoid::Document
+ include Mongoid::Paperclip
+
+ has_mongoid_attached_file :image
+
+ validates_presence_of :image
+
+ delegate :url, :to => :image
+
+ def serializable_hash(options = nil)
+ options ||= {}
+ options[:methods] ||= []
+ options[:methods] << :url
+ super(options)
+ end
+end

0 comments on commit e738889

Please sign in to comment.