Vitrage allows you to store and manage your Rails application content as separated pieces of different types: text, image, slider, several-columned text etc. Pieces are objects of different Rails models, that have their specific views for show and edit actions. Vitrage allows you to edit the content pieces inline.
Put this line in your Gemfile:
gem 'vitrage'
Then run bundle install
.
After installing the gem, you need to run the generator.
bin/rails generate vitrage:install
The generator adds these files:
app/models/vitrage_owners_pieces_slot.rb
db/migrate/[timestamp]_create_vitrage_owners_pieces_slots.rb
and line to the routes.rb
file:
Vitrage.routes(self)
Now, migrate your database: bin/rake db:migrate
Require js in your js file (application.js
by default):
//= require jquery
//= require jquery_ujs
//= require jquery.remotipart
//= require vitrage/vitrage
Vitrage needs jquery, jquery_ujs and jquery.remotipart for correct work. If you have this scripts already required, just skip inserting they strings.
Require vitrage css in your css file (application.css
by default):
*= require vitrage/vitrage
Add to any models you want to use vitrage content pieces line:
acts_as_vitrage_owner
Add render call to the show
view:
<%= show_vitrage_for @object %>
Add render call to the edit
view:
<%= edit_vitrage_for @object %>
Content pieces it is necessary parts of Vitrage. By default we have no pieces. Describes process of creating simple content piece only with text field.
bin/rails generate vitrage:piece Text body:text
The generator adds these files:
db/migrate/[timestamp]_create_vtrg_texts.rb
app/models/vitrage_pieces/vtrg_text.rb
app/views/vitrage/_vtrg_text.html.erb
app/views/vitrage/_vtrg_text_form.html.erb
# ... and more
Migrate your database: bin/rake db:migrate
Add name of content piece model to PIECE_CLASSES_STRINGS
array constant
of VitrageOwnersPiecesSlot model.
Add styles for add new block button:
.vtrg-new-block-kinds .vtrg-text { background: red; }
Do not forget about piece view partials.
PiecesController
have actions for vitrage pieces.
If you need to override controller, create new controller, inherited from Vitrage::PiecesController
:
class VitragePiecesController < Vitrage::PiecesController
# add devise authorization as option
before_action :authenticate_admin_user!
end
And add parameter controller
to routes method call with underscored and pluralized controller name:
Vitrage.routes(self, controller: 'vitrage_pieces')
Vitrage is released under the MIT License.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Feel free to use code of the project as you want, create issues or make pull requests.