Weeler

Gem Version Build Status Coverage Status Code Climate

CMS for weby.lv projects.

Installation

Add this line to your application's Gemfile:

gem 'weeler'

And then execute:

$ bundle

Or install it yourself as:

$ gem install weeler

Setup

Run weeler generator:

$ rails g weeler:install

This will generate follwing files:

  • config/initializers/weeler.rb
  • db/migrate/xxxxxxxxxxxxxx_create_weeler_seos.rb
  • db/migrate/xxxxxxxxxxxxxx_create_weeler_settings.rb
  • db/migrate/xxxxxxxxxxxxxx_create_weeler_translations.rb
  • db/migrate/xxxxxxxxxxxxxx_translate_weeler_seos.rb
  • app/controllers/weeler/application_controller.rb
  • lib/assets/javascripts/weeler/app/index.js
  • lib/assets/stylesheets/weeler/app/index.css
  • your route file will be appended

Following will be appended to your route file:

mount_weeler_at "weeler" do 
  # weeler_resources :example, include_in_weeler_menu: true 
  # Also you orderable and imageable concerns 
end

And then migrate database:

$ rake db:migrate

Weeler Structure

- app
-- controllers
--- weeler
---- application_controller.rb
-- views
--- weeler
- lib
-- assets
--- javascripts
---- weeler
----- app
------ index.js
--- stylesheets
---- weeler
----- app
------ index.css

Usage

Controllers, Views, Routes

Place weeler backend controllers in app/controllers/weeler/ directory and view files in app/views/weeler directory. Then add a route, a resource weeler_resources to this controller inside mount_weeler_at in config/routes.rb All weeler contollers have to extend Weeler::BaseController.

If you want your controller work under menu section, you should extend one of:

  • Weeler::AdministrationController - for administration section;
  • Weeler::ContentController - for content section;

Then you should append config.content_menu_items or config.administration_menu_items array with hash that contains: name for submenu name and weeler_path as string for relative weeler path. E.g.:

config.content_menu_items = [
  {name: "Posts",         weeler_path: "posts"},
  {name: "Post comments", weeler_path: "comments"}
]

acts_as_restful

Weeler action controller method. It creates all restful actions for action controller. Create a controller for your model (e.g. Post) what you want to administrate in weeler. Add method acts_as_restful Post and permit params for your resource - option permit_params. Also you can paginate - add option paginate e.g.

class Weeler::PostController < Weeler::ContentController
  acts_as_restful Post, permit_params: [:title, :body], paginate: 50
end

It will handle :index, :new, :edit, :update, :destroy, :order, :activation and :remove_image actions

For permiting custom by role or permiting all params (permit!), you must add block permit_params: -> (params) { params.require(:post).permit! }

You can override redirect path after :create, :update, :destroy actions. You can do this by overriding private methods in your controller.

def after_create_path
  { action: :edit, id: @item.id }
end

def after_update_path
  { action: :edit, id: @item.id }
end

def after_destroy_path
  { action: :index }
end

You should implement form file with your own active record attributes. To do that, create form.html.haml in views/weeler/_YOUR_RESOURCE/form.html.haml where _YOUR_RESOURCE is name of your resource.

Also you can override all standart restful action view and implement, if you need, _filter.html.haml

View partials for restful controllers:

Weeler have default views for index, new, edit actions. You should override _form.html.haml partial.

View helper image_upload_field :

Weeler action view helper method. It creates file upload field with info and preview for image.

e.g.

<%= f.image_upload_field :image, size_info: "270x294" %>

It creates:

<div class="col-lg-10 col-md-10">
  <label class="col-lg-2 col-md-2 control-label" for="object_image">Image</label><div class="col-lg-5 col-md-5"><div class="row"><div class="col-lg-12 col-md-12"><input class="form-control" id="object_image" name="object[image]" type="file"></div></div><div class="row"><div class="col-lg-12 col-md-12">Size should be 270x294</div></div></div><div class="col-lg-5 col-md-5"><div class="row"><div class="col-lg-12 col-md-12"><img alt="Name" src="/images/name.jpg" style="height: 80px;"></div></div></div>
</div>

If you use another image handler than Paperclip, you can also pass image_url_method for image preview.

Also with remove_image action in controller and route for that, it removes only image from object.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request