Skip to content

phsacramento/loldesign_publisher

 
 

Repository files navigation

Loldesign Publisher

About

Loldesign Publisher gem has the feature to make changes to views in order to leave it more enjoyable, also providing a laterally administrative menu.


Getting Started

Open Gemfile file and add gem to project:

gem "loldesign_publisher", '1.3.4'

Run command:

$ bundle install

Installing

+Loldesign Publisher+ gem depends of configuration files that are not automatically installed by default when you run the bundle install.

You must run the following command to enable gem:

rails generate loldesign_publisher:install

Run the command above to make available the function that allows to controllers inherit of LoldesignPublisher::PublisherController to views use.


Customize the Left Menu

Will be available in the config folder the file: loldesign_publisher.yml

This file contains the following code:

paths:
  logo:   'loldesign_publisher/logo.svg'
  logout: 'javascript://'

  menu_links:
    banners:   
      name: 'Banner Home'
      path: users_path
    recipes:
      name: 'Recipes'
      path: recipes_path
    schedules: 
      name: 'Schedule / Cources'
      path: schedules_path

page_title: 'Loldesign Publisher'
  • logo: ‘loldesign_publisher/logo.svg’, It is the path to image above the side menu

  • logout: ‘javascript://’, Is used to end the session by default is disabled, to enable it is necessary to use the devise gem for user authentication.

  • menu_links:, From menu_links are available blocks of code in which banners is the controller’s name, but without the rest of the name, example: banners_controller.rb, the name is fictitious banners in your project, you must enter the corresponding names to their controllers.

  • name: ‘Banner Home’, It’s receive one of any name your choice for the menu link.

  • path: users_path, Receives the route by which you want the link to answer.

  • page_title: ‘Loldesign Publisher’, The string specified here will be the name that is displayed in the browser tab.


Enable Loldesign Publisher

Add to controller:

class NameOfController < LoldesignPublisher::PublisherController

Helpers

Building Index Page

  • Title

<%= title_page "Title of Page" %>

It is a function that takes a string as a parameter, a string is automatically formatted and aligned as the title of the page in question.

  • Subtitle

subtitle: 'Subtitle of Page'

It’s a minor title. It should be added in the same line as the title page, and separated only by commas.

  • Add Resource

add_resource 'New Button', path_to_url

This helper create a button that lead the User to the desired path

  • Implementing Table #1

<table class='table-page'> content of table </table>

This HTML tag when added to any table, causes it to be automatically formatted, both the HTML and CSS.

  • Implementing Table #2

<%= display_list_for(@examples, fields: 5) %>

This ruby code list every registration, separate by lines, the part of the code @examples renders the partial _example.html.erb from the controller and need to have the same name as the controller. The parameter fields with the number 5, is the number of fields in the table, even when there is not any, it merges the 5 existing columns or not, and displays the message “No records found”.

  • Implement Table #3 (partial)

Using the example given above. Creates a button to edit the record

<%= edit_resource edit_example_path(example) %>

Creates a button to remove the record

<%= remove_resource(example_path(example), {})%>

Examples

These examples below uses the model establishment, and address the helper listed above previously.

---Index.html.erb---
<%= title_page 'Estabelecimentos' %>
<%= add_resource 'Novo Estabelecimento', new_admin_establishment_path %>

<%= render partial: 'filters' %>

<table class='table-page'>
  <thead>
    <tr>
      <th>Nome Fantasia</th>
      <th>Situação</th>
      <th>Tipo de Estabelecimento</th>
      <th>Condição</th>
      <th>&nbsp;</th>
    </tr>
  </thead>

  <tbody>
    <%= display_list_for(@establishments, fields: 5) %>
  </tbody>
</table>

<%= will_paginate @establishments %>

---_establishment.html.erb---
<tr class="<%= !establishment.status ? 'selected' : ''%>">
  <td><%= link_to establishment.fantasy_name, edit_admin_establishment_path(establishment), :class => "list-edit" %></td>
  <td><%= establishment.status_text %></td>
  <td><%= establishment.establishment_type_text %></td>
  <td><%= establishment.aasm.human_state %></td>
  <td>
    <%= edit_resource edit_admin_establishment_path(establishment) %>
    <%= remove_resource(admin_establishment_path(establishment), {})%>
  </td>
</tr>

Building _form.html.erb

In the _form.html.erb we create a formulary with two or three columns, as we put the fields to be filled.

  • simple_form_for

Within this ruby code goes all the contents of the form

<%= simple_form_for @establishment do |f| %>
  content of form
<% end %>
  • Section with two or three columns

Within this html tag goes article and fields necessary for the construction of _form.

<section class='three-columns'>
  content of section
</section>
  • Articles

Each article is one of the columns created by section

<article class='column'>
  fields of the form
</article>
  • Footer

The footer creates two buttons one to save and one to cancel the session.

<footer>
  <%= submit_button f %>
  <%= cancel_action :back %>
</footer>

Examples

Here is an code with the examples above:

<%= simple_form_for @user do |f| %>
  <section class='three-columns'>
    <article class='column'>
      <%= f.input :name, label: false, placeholder: 'Nome' %>
      <%= f.input :email, label: false, placeholder: 'E-mail' %>
      <%= f.input :password, label: false, placeholder: 'Senha', input_html: {class: 'small'} %>
      <%= f.input :active, label: 'Ativo' %>
    </article>
    <article class='column'>
      <%= f.input :description, label: false, placeholder: 'Descrição' %>
    </article>
    <article class='column'>
      <%= f.input :name, label: false, placeholder: 'Data', input_html: {class: 'date'}%>
      <%= f.input :name, label: false, placeholder: 'CPF', input_html: {class: 'cpf'} %>
    </article>
  </section>  

  <footer>
    <%= submit_button f %>
    <%= cancel_action :back %>
  </footer>
<% end -%>

contiuar: loldesign_publisher:install / loldesign_publisher:mailer_config / loldesign_publisher:views


endereços uteis: bitbucket.org/loldesign/loldesign_publisher/src/8aa1fd8d9650/app/?at=master


bitbucket.org/loldesign/lol_crud_generator/src


LoldesignPublisher

This project rocks and uses MIT-LICENSE.

About

LolDesign Publisher is a Rails engine that provides easy way to create admin interfaces

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 66.4%
  • JavaScript 15.4%
  • Ruby 13.5%
  • HTML 4.7%