diff --git a/CHANGELOG.md b/CHANGELOG.md index d0ef15c..c842a94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 1091583..57fa801 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -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| + 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 diff --git a/lib/generators/haml/scaffold/scaffold_generator.rb b/lib/generators/haml/scaffold/scaffold_generator.rb new file mode 100644 index 0000000..2ac43b1 --- /dev/null +++ b/lib/generators/haml/scaffold/scaffold_generator.rb @@ -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 diff --git a/lib/generators/haml/scaffold/templates/_blank.html.haml b/lib/generators/haml/scaffold/templates/_blank.html.haml new file mode 100644 index 0000000..efa95fb --- /dev/null +++ b/lib/generators/haml/scaffold/templates/_blank.html.haml @@ -0,0 +1 @@ +%h1 Your blank message here \ No newline at end of file diff --git a/lib/generators/haml/scaffold/templates/_filters.html.haml b/lib/generators/haml/scaffold/templates/_filters.html.haml new file mode 100644 index 0000000..a35c107 --- /dev/null +++ b/lib/generators/haml/scaffold/templates/_filters.html.haml @@ -0,0 +1 @@ +%h1 Your filters here \ No newline at end of file diff --git a/lib/generators/haml/scaffold/templates/_list.html.haml b/lib/generators/haml/scaffold/templates/_list.html.haml new file mode 100644 index 0000000..3c914f8 --- /dev/null +++ b/lib/generators/haml/scaffold/templates/_list.html.haml @@ -0,0 +1 @@ +%h1 Your list here \ No newline at end of file diff --git a/lib/generators/haml/scaffold/templates/single_entry.html.haml b/lib/generators/haml/scaffold/templates/single_entry.html.haml new file mode 100644 index 0000000..fea1441 --- /dev/null +++ b/lib/generators/haml/scaffold/templates/single_entry.html.haml @@ -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 \ No newline at end of file diff --git a/lib/templates/haml/scaffold/_filters.html.haml b/lib/templates/haml/scaffold/_filters.html.haml new file mode 100644 index 0000000..0769bfb --- /dev/null +++ b/lib/templates/haml/scaffold/_filters.html.haml @@ -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[1..@search.size-4] %>_cont, label: false, input_html: {class: 'form-control'}, placeholder: 'Quick search...' + %span.input-group-btn + = button_tag( class: 'btn') do + %i.icon-search \ No newline at end of file diff --git a/lib/templates/haml/scaffold/_list.html.haml b/lib/templates/haml/scaffold/_list.html.haml new file mode 100644 index 0000000..6fabf94 --- /dev/null +++ b/lib/templates/haml/scaffold/_list.html.haml @@ -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 %> \ No newline at end of file diff --git a/lib/templates/haml/scaffold/index.html.haml b/lib/templates/haml/scaffold/index.html.haml index 5cd4f0e..21584fa 100644 --- a/lib/templates/haml/scaffold/index.html.haml +++ b/lib/templates/haml/scaffold/index.html.haml @@ -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[1..@search.size-4] %>_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