Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

weby-lv/weeler

Repository files navigation

Weeler

Gem Version Build Status Coverage Status Code Climate

Installation

Rails 6.0

2.0.0 version only supports Rails 6.0 and ruby 2.5 or higher version. In Gemfile include:

gem 'weeler', '~> 2.0'

Rails 5.0

1.6.0 version only supports Rails 5.0 and ruby 2.2.2 and higher version. In Gemfile include:

gem 'weeler', '~> 1.6'

Rails 4.2

gem 'weeler', '~> 1.5'

After specifying necessary gems in Gemfile run

bundle install

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.

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

Or you can override what happens after successful :create, :update, :destroy actions. You can do this by overriding private methods in your controller.

def after_create_action
  redirect_to( after_create_path, {:notice => "Successfully created item"} )
end

def after_update_action
  redirect_to( after_update_path, {:notice => "Successfully updated item"} )
end

def after_destroy_action
  redirect_to( after_destroy_path, {:notice => "Successfully destroyed item"})
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.

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