Skip to content

artursbraucs/weeler

 
 

Repository files navigation

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

It will generate:

  • weeler.rb setting file in config/initializers folder;
  • migrations for translation, settings and object seos;
  • application_controller.rb in weeler controller scope. It is the parent controller of all weeler controllers;
  • assets in lib/assets for modify, append new javascript or style for weeler backend.

And then migrate database:

$ rake db:migrate

Usage

Adding controllers and views

Create controllers and views in app/controller/weeler and app/view/weeler and then add routes in mount_weeler_at block in config/routes.rb file. There is no limitation or DCL for that. Also you need to extend at least Weeler::BaseController if you expect that weeler work as expected.

Menu

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 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

Packages

No packages published

Languages

  • Ruby 96.4%
  • CSS 1.9%
  • JavaScript 1.3%
  • CoffeeScript 0.4%