Module: Poodle::ActionView::ThemeHelper

Defined in:
lib/poodle/action_view/theme_helper.rb

Overview

This module creates Bootstrap wrappers around basic View Tags

Instance Method Summary collapse

Instance Method Details

#clear_tag(height = nil) ⇒ Object



132
133
134
135
# File 'lib/poodle/action_view/theme_helper.rb', line 132

def clear_tag(height=nil)
  height_class = height ? " cl-#{height}" : ""
  (:div, "", class: "clearfix#{height_class}")
end

#theme_button(text, icon, url, options = {}) ⇒ Object

theme_button is used to create poodle like buttons which has built in classes and icons e.g:

theme_button('New Project', 'plus', new_admin_project_path)

The above is equivalent to

link_to raw("<i class='fa fa-plus mr-10'></i><span class='btn-text'> New Project</span>"), new_admin_project_path, :class=>"btn btn-primary pull-right ml-5", :remote=>true

And produces the following html

<a class="btn btn-primary pull-right ml-5" data-remote="true" href="/admin/projects/new"><i class="fa fa-plus mr-10"></i><span class="btn-text"> New Project</span></a>


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/poodle/action_view/theme_helper.rb', line 27

def theme_button(text, icon, url, options={})
  options.reverse_merge!(
    method: :get,
    remote: true,
    btn_type: :primary,
    btn_size: :md,
    classes: "pull-right ml-5 mb-5",
    data: {}
  )
  display_content = raw(theme_fa_icon(icon)+theme_button_text(text))
  link_to(display_content, url, :class=>"btn btn-#{options[:btn_type]} btn-#{options[:btn_size]} #{options[:classes]}", :remote=>options[:remote], method: options[:method], data: options[:data])
end

#theme_button_text(text) ⇒ Object

theme_button_text(‘New Project’) <span class=‘btn-text’> New Project</span>



16
17
18
# File 'lib/poodle/action_view/theme_helper.rb', line 16

def theme_button_text(text)
  "<span class='btn-text'> #{text}</span>"
end

#theme_delete_button(url, options = {}) ⇒ Object

Example

theme_delete_button(admin_project_path(@project))

is equivalent to:


link_to raw(“<i class="fa fa-trash "></i> Delete”), admin_project_path(@project), method: :delete, data: { confirm: ‘Are you sure?’ }, :class=>“btn btn-danger btn-xs pull-right”, :remote=>true



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/poodle/action_view/theme_helper.rb', line 63

def theme_delete_button(url, options={})
  options.reverse_merge!(
    text: "Delete",
    icon: "trash",
    method: :delete,
    remote: true,
    btn_type: :danger,
    btn_size: :xs,
    classes: "pull-right ml-10",
    data: { confirm: 'Are you sure?' }
  )
  theme_button(options[:text], options[:icon], url, options)
end

#theme_detail_box(collection, **options) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/poodle/action_view/theme_helper.rb', line 214

def theme_detail_box(collection, **options)
  options.reverse_merge!(
    show_partial: "show",
    new_partial: "form",
    edit_partial: "form",
    index_partial: "show",
  )
  case params[:action]
  when "show"
    render partial: options[:show_partial]
  when "new"
    render partial: options[:new_partial]
  when "edit"
    render partial: options[:edit_partial]
  when "index"
    collection.empty? ? (theme_panel_message(I18n.translate("forms.no_results"))) : render(partial: options[:index_partial])
  else
    theme_panel_message(I18n.translate("forms.no_results"))
  end
end

#theme_drop_down(collection, method_name, **options) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/poodle/action_view/theme_helper.rb', line 109

def theme_drop_down(collection, method_name, **options)
  options.reverse_merge!(
    scope: :admin
  )
  (:div, class: "btn-group mt-10 mb-10", style: "width:100%;") do
    button_tag(type: 'button', :class => "btn btn-default btn-block dropdown-toggle", "data-toggle" => "dropdown") do
      raw("Choose a Project" + (:span, "", class: "caret"))
    end +
    (:ul, class: "dropdown-menu", role: "menu") do
      li_array = []
      collection.each do |item|
        li_array << (:li) do
          url = main_app.url_for([options[:scope], item])
          link_to item.send(method_name), url, :remote => true
        end
      end
      raw(li_array.join(" ")) +
      (:li, link_to_next_page(collection, 'Next Page', :remote => true)) +
      (:li, link_to_previous_page(collection, 'Previous Page', :remote => true))
    end
  end
end

#theme_edit_button(url, options = {}) ⇒ Object

Example

theme_edit_button(edit_admin_project_path(@project))

is equivalent to:


link_to raw(“<i class="fa fa-edit mr-5"></i> Edit”), edit_admin_project_path(@project), :class=>“btn btn-default btn-xs pull-right ml-10”, :remote=>true %>



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/poodle/action_view/theme_helper.rb', line 45

def theme_edit_button(url, options={})
  options.reverse_merge!(
    text: "Edit",
    icon: "edit",
    method: :get,
    remote: true,
    btn_type: :default,
    btn_size: :xs,
    classes: "pull-right ml-10"
  )
  theme_button(options[:text], options[:icon], url, options)
end

#theme_fa_icon(icon_text, size = "") ⇒ Object

theme_fa_icon(‘plus’) <i class=‘fa fa-plus’></i> theme_fa_icon(‘plus’, ‘lg’) <i class=‘fa fa-plus fa-lg’></i>



9
10
11
12
# File 'lib/poodle/action_view/theme_helper.rb', line 9

def theme_fa_icon(icon_text, size="")
  size_class = %w{lg 2x 3x 4x 5x}.include?(size.strip) ? " fa-#{size.strip}" : ""
  "<i class='fa fa-#{icon_text}#{size_class}'></i>"
end

#theme_heading(heading, icon = '') ⇒ Object

theme_heading(heading) theme_heading(heading, icon=‘cog’) <div class=“row mb-10”>

<div class="fs-22 col-sm-12"><i class='fa fa-rub fa-lg mr-10'></i>Manage Projects</div>

</div>



82
83
84
85
86
87
88
# File 'lib/poodle/action_view/theme_helper.rb', line 82

def theme_heading(heading, icon='')
   :div, class: "row mb-10" do
     :div, class: "fs-22 col-sm-12" do
      raw((icon ? theme_fa_icon(icon, 'lg') : "") + " #{heading}")
    end
  end
end

#theme_item_description(text, limit = 120, classes = "text-color-grey fs-12") ⇒ Object

Example

theme_item_description(project.client.name, 120)

is equivalent to:


<div class="text-color-grey fs-12"><%= project.client.description %></div>


209
210
211
212
# File 'lib/poodle/action_view/theme_helper.rb', line 209

def theme_item_description(text, limit=120, classes = "text-color-grey fs-12")
  description = scrap_word(text, limit)
  (:div, description, class: classes)
end

#theme_item_sub_title(text, classes = "text-color-red fs-14") ⇒ Object

Example

theme_item_sub_title(project.client.name)

is equivalent to:


<div class="text-color-red fs-14"><%= project.client.name if project.client %></div>


199
200
201
# File 'lib/poodle/action_view/theme_helper.rb', line 199

def theme_item_sub_title(text, classes = "text-color-red fs-14")
  (:div, text, class: classes)
end

#theme_item_title(title, url, classes = "text-color-blue fs-16") ⇒ Object

Example

theme_item_title(project.name, admin_project_path(project))

is equivalent to:


<%= link_to project.name, admin_project_path(project), :remote=>true, :class=>"text-color-blue fs-16" %>


189
190
191
# File 'lib/poodle/action_view/theme_helper.rb', line 189

def theme_item_title(title, url, classes = "text-color-blue fs-16")
  link_to(title, url, :remote=>true, :class=>classes)
end

#theme_more_widget(object, **options) ⇒ Object

Example

theme_more_widget(object, data_columns=[:id, :created_at, :updated_at], super_admin = true)

is equivalent to:


<% if @current_user.is_super_admin? %>

<%= render :partial => "widgets/more_details", :locals=>{
                      :data_model => @project,
                      :data_columns => [:id, :created_at, :updated_at],
                      :heading => "Technical Details",
                      :display_footer => false} %>

<% end %>



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/poodle/action_view/theme_helper.rb', line 246

def theme_more_widget(object, **options)
  options.reverse_merge!(
    data_columns: [:id, :created_at, :updated_at],
    super_admin: false,
    heading: "Technical Details"
  )
  display = options[:super_admin] ? @current_user.is_super_admin? : true
  render(:partial => "widgets/more_details",
              :locals=>{:data_model => object,
                        :data_columns => options[:data_columns],
                        :heading => options[:heading],
                        :display_footer => false}) if display
end

#theme_paginate(collection) ⇒ Object

Example

theme_paginate(@projects)

is equivalent to:


<div class=“cl”></div> <% if @projects.any? %>

<%= content_tag :div, :class=>"pull-right" do %>
  <%= paginate @projects, :remote => true %>
<% end %>

<% end %> <div class=“cl”></div>




150
151
152
153
154
155
156
157
# File 'lib/poodle/action_view/theme_helper.rb', line 150

def theme_paginate(collection)
  return "" if collection.empty?
  clear_tag(10) +
  (:div, :class=>"pull-right") do
    paginate(collection, :remote => true)
  end +
  clear_tag(10)
end

#theme_panel_description(text, classes = "fs-14") ⇒ Object

Example

theme_panel_description(@project.pretty_url, "fs-14")
theme_panel_description(@project.description, "fs-14 mt-10")

is equivalent to:


<div class=“fs-14”><%= @project.pretty_url %></div> <div class=“fs-14 mt-10”><%= @project.description %></div>



285
286
287
# File 'lib/poodle/action_view/theme_helper.rb', line 285

def theme_panel_description(text, classes="fs-14")
  (:div, text, class: classes)
end

#theme_panel_heading(text, classes = "fs-24 text-color-green") ⇒ Object

Example

theme_panel_heading(@project.name)

is equivalent to:


<div class=“fs-24 text-color-green”><%= @project.name %></div>



265
266
267
# File 'lib/poodle/action_view/theme_helper.rb', line 265

def theme_panel_heading(text, classes="fs-24 text-color-green")
  (:div, text, class: classes)
end

#theme_panel_message(message) ⇒ Object

Example

theme_panel_message("No Results found")

is equivalent to:


<div class="panel panel-default text-color-grey p-80 text-align-center" style="height:200px;">
 "No Results found"
</div>


167
168
169
170
171
# File 'lib/poodle/action_view/theme_helper.rb', line 167

def theme_panel_message(message)
  (:div, class: "panel panel-default panel-message text-color-grey p-80 text-align-center", style: "height:200px;") do
    raw(message)
  end
end

#theme_panel_sub_heading(text, url, classes = "fs-16 text-color-red") ⇒ Object

Example

theme_panel_sub_heading(@project.name, admin_client_path(@project.client))

is equivalent to:


link_to(@project.client.name, admin_client_path(@project.client), class: “fs-16 text-color-red”)



274
275
276
# File 'lib/poodle/action_view/theme_helper.rb', line 274

def theme_panel_sub_heading(text, url, classes="fs-16 text-color-red")
  link_to(text, url, class: classes)
end

#theme_panel_title(title, classes = "") ⇒ Object

Example

theme_panel_title("Team Members")

is equivalent to:


<h3 class="panel-title">Team Members</h3>


179
180
181
# File 'lib/poodle/action_view/theme_helper.rb', line 179

def theme_panel_title(title, classes="")
  (:h3, title, class: "panel-title #{classes}")
end

#theme_search_form(cls, url, method = :get, remote = true, text = "Search!") ⇒ Object

theme_search_form is a helper to create a form to filter the results by entering a search query



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/poodle/action_view/theme_helper.rb', line 91

def theme_search_form(cls, url, method=:get, remote=true, text="Search!")
  form_for cls.new, :url => url,
        :method => method, :remote=>remote,
        :html=>{:class=>"pull-right", :style=>"margin-bottom:0px;"} do |f|
     :div, class: "input-group" do
      text_field_tag('query','', :class => 'form-control', :placeholder => 'Search ...') +
      (:span, class: "input-group-btn") do
        button_tag(type: 'submit', class: "btn btn-default") do
          raw(theme_fa_icon('search') +
          (:span, class: "btn-text") do
            " " + text
          end)
        end
      end
    end
  end
end