Skip to content

Commit

Permalink
#20 blank list and filter partial added to scaffold generator
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdilek committed Sep 11, 2013
1 parent 62039a1 commit 361c26d
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#### [Current]

####
* [7c1f307](../../commit/7c1f307) - __(Muhammet DİLEK)__ [#20](../../issues/20) show_for config added
* [ca81bb4](../../commit/ca81bb4) - __(Muhammet DİLEK)__ [#20](../../issues/20) detail page added
* [19c5718](../../commit/19c5718) - __(Ahmet Sezgin Duran)__ Update README.md
* [560fd1b](../../commit/560fd1b) - __(Ahmet Sezgin Duran)__ [#24](../../issues/24) Clean up code and add login links to README.md
* [c581aa2](../../commit/c581aa2) - __(Ahmet Sezgin Duran)__ [#24](../../issues/24) Create default users for development and update README.md
* [1943cab](../../commit/1943cab) - __(Muhammet DİLEK)__ [#20](../../issues/20) edit and new page added
* [6206a77](../../commit/6206a77) - __(Muhammet DİLEK)__ [#20](../../issues/20) pagination view added
Expand Down
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20130905072700) do
ActiveRecord::Schema.define(version: 20130911070035) do

create_table "admins", force: true do |t|
t.string "email", default: "", null: false
Expand All @@ -31,6 +31,13 @@
add_index "admins", ["email"], name: "index_admins_on_email", unique: true
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true

create_table "products", force: true do |t|

This comment has been minimized.

Copy link
@onurozgurozkan

onurozgurozkan Sep 11, 2013

@muhammetdilek products ? 😧

This comment has been minimized.

Copy link
@adamdilek

adamdilek Sep 11, 2013

Author Contributor

@onurozgurozkan Product my test model for generator. I fix it.

t.string "name"
t.string "barcode"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
Expand Down
48 changes: 48 additions & 0 deletions lib/generators/haml/scaffold/scaffold_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'rails/generators/erb/scaffold/scaffold_generator'

module Haml
module Generators
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
source_root File.expand_path("../templates", __FILE__)

def copy_view_files
available_views.each do |view|
filename = filename_with_extensions(view)
if filename == "_#{singular_table_name}.html.haml"
#create_file File.join("app/views", controller_file_path, "_#{singular_table_name}.html.haml") do
# hostname = ask("What is the virtual hostname I should use?")
# "vhost.name = #{hostname}"
#end

template 'single_entry.html.haml', File.join("app/views", controller_file_path, filename)
else
template "#{view}.html.haml", File.join("app/views", controller_file_path, filename)
end
end
end

hook_for :form_builder, :as => :scaffold

def copy_form_file
if options[:form_builder].nil?
filename = filename_with_extensions("_form")
template "_form.html.haml", File.join("app/views", controller_file_path, filename)
end
end

protected

def available_views
file = "_#{singular_table_name}"
list = %w(index edit show new _list _blank _filters)
list << file
list
end

def handler
:haml
end

end
end
end
1 change: 1 addition & 0 deletions lib/generators/haml/scaffold/templates/_blank.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%h1 Your blank message here
1 change: 1 addition & 0 deletions lib/generators/haml/scaffold/templates/_filters.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%h1 Your filters here
1 change: 1 addition & 0 deletions lib/generators/haml/scaffold/templates/_list.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%h1 Your list here
12 changes: 12 additions & 0 deletions lib/generators/haml/scaffold/templates/single_entry.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%tr
%td= <%= singular_table_name %>.id
<% for attribute in attributes -%>
%td= <%= singular_table_name %>.<%= attribute.name %>
<% end -%>
%td.action
= link_to(<%= singular_table_name %>, class: 'btn btn-success', toogle: 'tooltip', title: t('tooltips.zoom')) do
%i.icon-zoom-in
= link_to(edit_<%= singular_table_name %>_path(<%= singular_table_name %>) , class: 'btn btn-info') do
%i.icon-edit
= link_to(<%= singular_table_name %>, class: 'btn btn-danger', method: :delete) do
%i.icon-trash
12 changes: 12 additions & 0 deletions lib/templates/haml/scaffold/_filters.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% @search = "" -%>
<% attributes.each { |attribute| @search += "_#{attribute.name}_or" } -%>
.table-header.row
.col-lg-9
TODO: Add filters here
.col-lg-3
= search_form_for @search, builder: SimpleForm::FormBuilder do |f|
.input-group
= f.input_field :<%= @search[[email protected]] %>_cont, label: false, input_html: {class: 'form-control'}, placeholder: 'Quick search...'
%span.input-group-btn
= button_tag( class: 'btn') do
%i.icon-search
27 changes: 27 additions & 0 deletions lib/templates/haml/scaffold/_list.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.panel-heading
%i.icon-table.icon-large
= t('tt.index', resource_name: <%= singular_table_name.capitalize %>.model_name.human)
.panel-tools
.btn-group
%a.btn{href: '#'}
%i.icon-wrench
Settings
%a.btn{href: '#'}
%i.icon-filter
Filters
%a.btn{href: <%= index_helper %>_path, data: {toggle: 'toolbar-tooltip'}, title: 'Reload'}
%i.icon-refresh
.badge= @<%= plural_table_name %>.total_entries
.panel-body.no-padding
= render 'filters'
%table.table
%thead
%tr
%th #
<% for attribute in attributes -%>
%th= sort_link(@search, :<%= attribute.name %>, t('activerecord.attributes.<%= singular_table_name %>.<%= attribute.name %>'))
<% end -%>
%th.actions
Actions
%tbody
= render @<%= plural_table_name %>
52 changes: 1 addition & 51 deletions lib/templates/haml/scaffold/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,59 +1,9 @@
<% @search = "" -%>
<% attributes.each { |attribute| @search += "_#{attribute.name}_or" } -%>

- content_for :toolbar do
= link_to new_<%= singular_table_name %>_path, class: 'btn btn-default' do
%i.icon-plus
= t('action_button.new', resource_name: <%= singular_table_name.capitalize %>.model_name.human)

.panel.tables
.panel-heading
%i.icon-table.icon-large
= t('tt.index', resource_name: <%= singular_table_name.capitalize %>.model_name.human)
.panel-tools
.btn-group
%a.btn{href: '#'}
%i.icon-wrench
Settings
%a.btn{href: '#'}
%i.icon-filter
Filters
%a.btn{href: <%= index_helper %>_path, data: {toggle: 'toolbar-tooltip'}, title: 'Reload'}
%i.icon-refresh
.badge= @<%= plural_table_name %>.total_entries
.panel-body.no-padding
.table-header.row
.col-lg-9
TODO: Add filters here
.col-lg-3
= search_form_for @search, builder: SimpleForm::FormBuilder do |f|
.input-group
= f.input_field :<%= @search[[email protected]] %>_cont, label: false, input_html: {class: 'form-control'}, placeholder: 'Quick search...'
%span.input-group-btn
= button_tag( class: 'btn') do
%i.icon-search
%table.table
%thead
%tr
%th #
<% for attribute in attributes -%>
%th= sort_link(@search, :<%= attribute.name %>, t('activerecord.attributes.<%= singular_table_name %>.<%= attribute.name %>'))
<% end -%>
%th.actions
Actions
%tbody
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
%tr
%td= <%= singular_table_name %>.id
<% for attribute in attributes -%>
%td= <%= singular_table_name %>.<%= attribute.name %>
<% end -%>
%td.action
= link_to(<%= singular_table_name %>, class: 'btn btn-success', toogle: 'tooltip', title: t('tooltips.zoom')) do
%i.icon-zoom-in
= link_to(edit_<%= singular_table_name %>_path(<%= singular_table_name %>) , class: 'btn btn-info') do
%i.icon-edit
= link_to(<%= singular_table_name %>, class: 'btn btn-danger', method: :delete) do
%i.icon-trash
= render 'list'

= will_paginate @<%= plural_table_name %>, renderer: BootstrapPagination::Rails, bootstrap: 3

0 comments on commit 361c26d

Please sign in to comment.