rails_dash 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -23,7 +23,7 @@ To generate a resource do:
23
23
  = Customize
24
24
 
25
25
  To protect the dash directory edit authorize filter in:
26
- app/controller/dash_controller.rb
26
+ app/controllers/dash_controller.rb
27
27
 
28
28
  To change the behavior of a resource:
29
29
  app/controllers/dash/model_controller.rb
@@ -36,3 +36,6 @@ To change the resource form edit:
36
36
 
37
37
  To change the resource grid edit:
38
38
  app/views/dash/model/index.html.html
39
+
40
+ To change the records in the grid and the filter behavior edit the filter scope in your resource model:
41
+ app/models/model.rb
@@ -3,8 +3,6 @@ module RailsDash
3
3
 
4
4
  before_filter :year
5
5
 
6
- layout 'dash'
7
-
8
6
  protected
9
7
 
10
8
  def year
@@ -5,20 +5,20 @@ module RailsDash
5
5
 
6
6
  def index
7
7
  @meta_title = @title = "#{@model.model_name.human :count => 2}"
8
- @records = @model.list(page, filter)
8
+ @records = @model.filter(filter).page(page)
9
9
  end
10
10
 
11
11
  def new
12
- @meta_title = @title = "#{t('global.add')} #{@model.model_name.human}"
12
+ @meta_title = @title = "#{t('dash.grid.add')} #{@model.model_name.human}"
13
13
  @record = @model.new
14
14
  render :form
15
15
  end
16
16
 
17
17
  def create
18
- @meta_title = @title = "#{t('global.add')} #{@model.model_name.human}"
18
+ @meta_title = @title = "#{t('dash.grid.add')} #{@model.model_name.human}"
19
19
  @record = @model.new(params[param])
20
20
  if @record.save
21
- redirect_with_flash(index_path, :success, t('flash.success.add'), params)
21
+ redirect_with_flash(index_path, :success, t('dash.flash.success.add'), params)
22
22
  else
23
23
  flash_errors @record
24
24
  render :form
@@ -26,16 +26,16 @@ module RailsDash
26
26
  end
27
27
 
28
28
  def show
29
- @meta_title = @title = "#{t('global.view')} #{@model.model_name.human}"
29
+ @meta_title = @title = "#{t('dash.grid.edit')} #{@model.model_name.human}"
30
30
  @record = @model.find(params[:id])
31
31
  render :form
32
32
  end
33
33
 
34
34
  def update
35
- @meta_title = @title = "#{t('global.view')} #{@model.model_name.human}"
35
+ @meta_title = @title = "#{t('dash.grid.edit')} #{@model.model_name.human}"
36
36
  @record = @model.find(params[:id])
37
37
  if @record.update_attributes(params[param])
38
- redirect_with_flash index_path, :success, t('flash.success.edit'), params
38
+ redirect_with_flash index_path, :success, t('dash.flash.success.edit'), params
39
39
  else
40
40
  flash_errors @record
41
41
  render :form
@@ -44,7 +44,7 @@ module RailsDash
44
44
 
45
45
  def destroy
46
46
  @model.destroy params[:id]
47
- redirect_with_flash index_path, :success, t('flash.success.delete')
47
+ redirect_with_flash index_path, :success, t('dash.flash.success.destroy')
48
48
  end
49
49
 
50
50
  protected
@@ -0,0 +1,24 @@
1
+ en:
2
+ dash:
3
+ flash:
4
+ success:
5
+ add: "Record added successfully."
6
+ edit: "Record edited successfully."
7
+ destroy: "Record destroyed successfully."
8
+ menu:
9
+ home: "Home"
10
+ session:
11
+ logout: "Logout"
12
+ footer:
13
+ copyright: "Dash © %{year}"
14
+ grid:
15
+ filter: "Filter"
16
+ actions: "Actions"
17
+ add: "Add"
18
+ edit: "Edit"
19
+ destroy: "Destroy"
20
+ pager:
21
+ first: "First"
22
+ previous: "Previous"
23
+ next: "Next"
24
+ last: "Last"
@@ -0,0 +1,24 @@
1
+ es:
2
+ dash:
3
+ flash:
4
+ success:
5
+ add: "Registro agregado correctamente."
6
+ edit: "Registro editado correctamente."
7
+ destroy: "Registro eliminiado correctamente."
8
+ menu:
9
+ home: "Inicio"
10
+ session:
11
+ logout: "Salir"
12
+ footer:
13
+ copyright: "Panel © %{year}"
14
+ grid:
15
+ filter: "Filtrar"
16
+ actions: "Acciones"
17
+ add: "Agregar"
18
+ edit: "Editar"
19
+ destroy: "Eliminar"
20
+ pager:
21
+ first: "Primero"
22
+ previous: "Anterior"
23
+ next: "Siguiente"
24
+ last: "Último"
@@ -4,8 +4,22 @@ module Dash
4
4
  source_root File.expand_path('../templates', __FILE__)
5
5
 
6
6
  def add_route
7
- gsub_file 'config/routes.rb', /namespace :dash(.*)/ do |match|
8
- "#{match}\n\n resources :#{table_name}"
7
+ insert_into_file 'config/routes.rb', :after => /namespace :dash(.*)/ do
8
+ "\n\n resources :#{table_name}"
9
+ end
10
+ end
11
+
12
+ def add_scope
13
+ insert_into_file "app/models/#{singular_name}.rb", :after => /class #{singular_name.camelize}(.*)/ do
14
+ "\n\n scope :filter, lambda { |filter| where('', :filter => \"%\#{filter}%\") }"
15
+ end
16
+ end
17
+
18
+ def add_menu
19
+ insert_into_file 'app/views/layouts/dash.html.haml', :before => /(.*)#session(.*)/ do
20
+ "#{' ' * 16}%li\n" +
21
+ "#{' ' * 18}%a{ :href => url_for([:dash, :#{table_name}]), :title => #{singular_name.camelize}.model_name.human(:count => 2) }\n" +
22
+ "#{' ' * 20}= #{singular_name.camelize}.model_name.human(:count => 2)\n"
9
23
  end
10
24
  end
11
25
 
@@ -1,5 +1,5 @@
1
1
  #options
2
2
  = form_tag request.fullpath, :method => 'get', :id => 'search' do
3
- = text_field_tag :q, (params[:q].present? ? params[:q] : t('layouts.dash.options.search_text')), :onblur => "if (this.value == '') {this.value = '#{t('layouts.dash.options.search_text')}';}", :onfocus => "if (this.value == '#{t('layouts.dash.options.search_text')}') {this.value = '';}"
3
+ = text_field_tag :q, (params[:q].present? ? params[:q] : t('dash.grid.filter')), :onblur => "if (this.value == '') {this.value = '#{t('dash.grid.filter')}';}", :onfocus => "if (this.value == '#{t('dash.grid.filter')}') {this.value = '';}"
4
4
  %a.button.action{ :href => url_for([:new, :dash, @model.name.underscore.to_sym]) }
5
- = t('global.add')
5
+ = t('dash.grid.add')
@@ -6,7 +6,7 @@
6
6
  %th
7
7
  = @model.human_attribute_name('created_at')
8
8
  %th.actions
9
- = t('global.actions')
9
+ = t('dash.grid.actions')
10
10
  - @records.each do |record|
11
11
  %tr
12
12
  %td
@@ -14,6 +14,6 @@
14
14
  %td
15
15
  = l(record.created_at)
16
16
  %td.actions
17
- = link_to(t('global.edit'), [:dash, record])
18
- = link_to(t('global.destroy'), [:dash, record], :method => :delete)
17
+ = link_to(t('dash.grid.edit'), [:dash, record])
18
+ = link_to(t('dash.grid.destroy'), [:dash, record], :method => :delete)
19
19
  = render :partial => 'dash/shared/pager', :locals => { :collection => @records }
@@ -2,7 +2,7 @@
2
2
  %html{:xmlns => 'http://www.w3.org/1999/xhtml', :'xml:lang' => I18n.locale, :lang => I18n.locale}
3
3
  %head
4
4
  %title= @meta_title
5
- = stylesheet_link_tag 'rails_dash/application', :media => 'all'
5
+ = stylesheet_link_tag 'railsdash/application', :media => 'all'
6
6
  = javascript_include_tag 'application'
7
7
  = csrf_meta_tags
8
8
  %body
@@ -12,11 +12,11 @@
12
12
  #menu
13
13
  %ul
14
14
  %li
15
- %a{ :href => rails_dash.root_path, :title => t('layouts.dash.menu.home') }
16
- = t('layouts.dash.menu.home')
15
+ %a{ :href => rails_dash.root_path, :title => t('dash.menu.home') }
16
+ = t('dash.menu.home')
17
17
  #session
18
- %a.button{ :href => '#', :title => t('layouts.dash.session.logout') }
19
- = t('layouts.dash.session.logout')
18
+ %a.button{ :href => '#', :title => t('dash.session.logout') }
19
+ = t('dash.session.logout')
20
20
  - if @title
21
21
  #header
22
22
  .holder
@@ -37,4 +37,4 @@
37
37
  #footer
38
38
  .holder
39
39
  %p#copyright
40
- = t('layouts.dash.footer.copyright', :year => @year)
40
+ = t('dash.footer.copyright', :year => @year)
@@ -3,10 +3,10 @@
3
3
  #pager
4
4
  - if pager.has_first_page?
5
5
  %a.first{ :href => pager.first_page_path }
6
- = t('global.first')
6
+ = t('dash.pager.first')
7
7
  - if pager.has_previous_page?
8
8
  %a.previous{ :href => pager.previous_page_path }
9
- = t('global.previous')
9
+ = t('dash.pager.previous')
10
10
  - if pager.navigation.has_less_pages?
11
11
  %span.ellipsis ...
12
12
  - for page in pager.navigation.pages
@@ -20,7 +20,7 @@
20
20
  %span.ellipsis ...
21
21
  - if pager.has_next_page?
22
22
  %a.next{ :href => pager.next_page_path }
23
- = t('global.next')
23
+ = t('dash.pager.next')
24
24
  - if pager.has_last_page?
25
25
  %a.last{ :href => pager.last_page_path }
26
- = t('global.last')
26
+ = t('dash.pager.last')
@@ -1,5 +1,5 @@
1
1
  module RailsDash
2
2
 
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
 
5
5
  end
@@ -1,5 +1,7 @@
1
1
  class Photo < ActiveRecord::Base
2
2
 
3
+ scope :filter, lambda { |filter| where('', :filter => "%#{filter}%") }
4
+
3
5
  attr_accessible :name
4
6
 
5
7
  class << self
@@ -6,7 +6,7 @@
6
6
  %th
7
7
  = @model.human_attribute_name('created_at')
8
8
  %th.actions
9
- = t('global.actions')
9
+ = t('dash.grid.actions')
10
10
  - @records.each do |record|
11
11
  %tr
12
12
  %td
@@ -14,6 +14,6 @@
14
14
  %td
15
15
  = l(record.created_at)
16
16
  %td.actions
17
- = link_to(t('global.edit'), [:dash, record])
18
- = link_to(t('global.destroy'), [:dash, record], :method => :delete)
17
+ = link_to(t('dash.grid.edit'), [:dash, record])
18
+ = link_to(t('dash.grid.destroy'), [:dash, record], :method => :delete)
19
19
  = render :partial => 'dash/shared/pager', :locals => { :collection => @records }
@@ -1,5 +1,5 @@
1
1
  #options
2
2
  = form_tag request.fullpath, :method => 'get', :id => 'search' do
3
- = text_field_tag :q, (params[:q].present? ? params[:q] : t('layouts.dash.options.search_text')), :onblur => "if (this.value == '') {this.value = '#{t('layouts.dash.options.search_text')}';}", :onfocus => "if (this.value == '#{t('layouts.dash.options.search_text')}') {this.value = '';}"
3
+ = text_field_tag :q, (params[:q].present? ? params[:q] : t('dash.grid.filter')), :onblur => "if (this.value == '') {this.value = '#{t('dash.grid.filter')}';}", :onfocus => "if (this.value == '#{t('dash.grid.filter')}') {this.value = '';}"
4
4
  %a.button.action{ :href => url_for([:new, :dash, @model.name.underscore.to_sym]) }
5
- = t('global.add')
5
+ = t('dash.grid.add')
@@ -3,10 +3,10 @@
3
3
  #pager
4
4
  - if pager.has_first_page?
5
5
  %a.first{ :href => pager.first_page_path }
6
- = t('global.first')
6
+ = t('dash.pager.first')
7
7
  - if pager.has_previous_page?
8
8
  %a.previous{ :href => pager.previous_page_path }
9
- = t('global.previous')
9
+ = t('dash.pager.previous')
10
10
  - if pager.navigation.has_less_pages?
11
11
  %span.ellipsis ...
12
12
  - for page in pager.navigation.pages
@@ -20,7 +20,7 @@
20
20
  %span.ellipsis ...
21
21
  - if pager.has_next_page?
22
22
  %a.next{ :href => pager.next_page_path }
23
- = t('global.next')
23
+ = t('dash.pager.next')
24
24
  - if pager.has_last_page?
25
25
  %a.last{ :href => pager.last_page_path }
26
- = t('global.last')
26
+ = t('dash.pager.last')
@@ -12,11 +12,14 @@
12
12
  #menu
13
13
  %ul
14
14
  %li
15
- %a{ :href => rails_dash.root_path, :title => t('layouts.dash.menu.home') }
16
- = t('layouts.dash.menu.home')
15
+ %a{ :href => rails_dash.root_path, :title => t('dash.menu.home') }
16
+ = t('dash.menu.home')
17
+ %li
18
+ %a{ :href => url_for([:dash, :photos]), :title => Photo.model_name.human(:count => 2) }
19
+ = Photo.model_name.human(:count => 2)
17
20
  #session
18
- %a.button{ :href => '#', :title => t('layouts.dash.session.logout') }
19
- = t('layouts.dash.session.logout')
21
+ %a.button{ :href => '#', :title => t('dash.session.logout') }
22
+ = t('dash.session.logout')
20
23
  - if @title
21
24
  #header
22
25
  .holder
@@ -37,4 +40,4 @@
37
40
  #footer
38
41
  .holder
39
42
  %p#copyright
40
- = t('layouts.dash.footer.copyright', :year => @year)
43
+ = t('dash.footer.copyright', :year => @year)
Binary file