easy_admin_ui 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.tmproj
2
+ pkg
data/README ADDED
@@ -0,0 +1,104 @@
1
+ Description
2
+ ===========
3
+
4
+ A very simple admin UI. If you need something more fancy look at ActiveScaffold.
5
+
6
+ Requirements
7
+ ============
8
+
9
+ * make_resourceful
10
+ * formtastic
11
+ * will_paginate
12
+
13
+ Tested with Rails 2.3.8.
14
+
15
+ To Do
16
+ =====
17
+
18
+ Some things are currently hardwired. It assumes you have your controllers below
19
+ admin/. I.e. admin_users_path.
20
+
21
+ Installation
22
+ ============
23
+
24
+ $ gem install easy_admin_ui
25
+
26
+ To use the rake tasks add:
27
+
28
+ require 'easy_admin_ui/tasks'
29
+
30
+ to your Rakefile.
31
+
32
+ How to use
33
+ ==========
34
+
35
+ In your controller:
36
+
37
+ class Admin::UsersController < ActionController::Base
38
+ easy_admin :per_page => 50,
39
+ :order => 'created_at',
40
+ :page_title => 'Users',
41
+ :columns => ['Login', 'Email', 'Created'],
42
+ :show_actions => true,
43
+ :skip_new => true
44
+ end
45
+
46
+ The model is infered by the make_resourceful plugin which is why we don't need
47
+ to specify it here. However, the object(s) returned will be named @item or
48
+ @items (for :index).
49
+
50
+ Then you need a partial below users/ named '_user.html.erb':
51
+
52
+ <%=
53
+ table_row(:id => "tr_user_#{user.id}", :class => "#{cyc = cycle("even", "odd")}",
54
+ :cells => [
55
+ h(user.login),
56
+ h(user.email),
57
+ date_hm(user.created_at),
58
+ ],
59
+ :actions => [
60
+ admin_edit_link(user),
61
+ admin_delete_link_with_confirmation(user)
62
+ ])
63
+ -%>
64
+
65
+ Copy icons:
66
+
67
+ $ rake easy_admin_ui:copy_assets
68
+
69
+ Manually copy the sample CSS.
70
+
71
+ You need to provide the _form.html.erb partials yourself.
72
+
73
+ You can always override the default templates by providing templates yourself.
74
+
75
+ Callbacks
76
+ =========
77
+
78
+ Index page only:
79
+
80
+ _index_after_title.html.erb
81
+ _index_after_table.html.erb
82
+
83
+ New/edit pages:
84
+
85
+ _modify_after_title.html.erb
86
+ _modify_after_form.html.erb
87
+
88
+ If these exist the more specific partials below will not be rendered.
89
+
90
+ Edit page only:
91
+
92
+ _edit_after_title.html.erb
93
+ _edit_after_form.html.erb
94
+
95
+ New page only:
96
+
97
+ _new_after_title.html.erb
98
+ _new_after_form.html.erb
99
+
100
+ Will be included on all actions no matter if other partials were present or
101
+ not:
102
+
103
+ _after_title.html.erb
104
+ _after.html.erb
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "easy_admin_ui"
8
+ gem.summary = "Easy Admin UI."
9
+ gem.description = "Very simple DRY admin UI."
10
+ gem.email = "martin@wulffeld.org"
11
+ gem.homepage = "http://github.com/wulffeld/easy_admin_ui"
12
+ gem.authors = ["Martin Moen Wulffeld"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,69 @@
1
+ /* Copy this to your main CSS if you like. */
2
+
3
+ /** easy start **/
4
+ table.easy {
5
+ border-collapse: normal;
6
+ margin-top: 4px;
7
+ }
8
+
9
+ table.easy th,
10
+ table.easy td {
11
+ font-family: "Helvetica Neue", Verdana, Arial, sans-serif;
12
+ font-size: 12px;
13
+ line-height: 14px;
14
+ }
15
+
16
+ table.easy td p {
17
+ margin: 0 0 10px 0;
18
+ }
19
+
20
+ table.easy th.wrap,
21
+ table.easy td.wrap {
22
+ white-space: normal;
23
+ }
24
+
25
+ /* Header cells. */
26
+ table.easy thead th {
27
+ background-color: #E6E6E6;
28
+ color: inherit;
29
+ border: 1px solid #FFF;
30
+ padding: 3px;
31
+ }
32
+
33
+ table.easy thead td.textright {
34
+ text-align: right;
35
+ }
36
+
37
+ /* Body cells. */
38
+ table.easy tbody td.blank {
39
+ background-color: inherit;
40
+ color: inherit;
41
+ border: none;
42
+ }
43
+
44
+ table.easy tbody td {
45
+ background-color: #FFF;
46
+ color: #333;
47
+ width: auto;
48
+ border-top: 1px dotted #DDD;
49
+ padding: 4px 3px;
50
+ }
51
+
52
+ table.easy tbody td.act {
53
+ margin: 0;
54
+ padding-top: 2px;
55
+ padding-bottom: 0;
56
+ min-width: 150px;
57
+ }
58
+
59
+ table.easy th.date,
60
+ table.easy td.date {
61
+ width: 80px;
62
+ }
63
+
64
+ table.easy th.datetime,
65
+ table.easy td.datetime {
66
+ width: 110px;
67
+ }
68
+
69
+ /** easy end **/
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{easy_admin_ui}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Martin Moen Wulffeld"]
12
+ s.date = %q{2010-07-27}
13
+ s.description = %q{Very simple DRY admin UI.}
14
+ s.email = %q{martin@wulffeld.org}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "assets/css/easy_admin_ui.css",
24
+ "assets/icons/classify.png",
25
+ "assets/icons/connect.png",
26
+ "assets/icons/delete.png",
27
+ "assets/icons/disconnect.png",
28
+ "assets/icons/pencil.png",
29
+ "assets/icons/show.png",
30
+ "easy_admin_ui.gemspec",
31
+ "lib/easy_admin_ui.rb",
32
+ "lib/easy_admin_ui/core_ext.rb",
33
+ "lib/easy_admin_ui/tasks.rb",
34
+ "lib/easy_admin_ui/view_helpers.rb",
35
+ "tasks/easy_admin_ui.rake",
36
+ "templates/easy_admin_ui/edit.html.erb",
37
+ "templates/easy_admin_ui/index.html.erb",
38
+ "templates/easy_admin_ui/new.html.erb"
39
+ ]
40
+ s.homepage = %q{http://github.com/wulffeld/easy_admin_ui}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.6}
44
+ s.summary = %q{Easy Admin UI.}
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ else
52
+ end
53
+ else
54
+ end
55
+ end
56
+
@@ -0,0 +1,93 @@
1
+ module EasyAdminUi
2
+ module CoreExt
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ attr_accessor :options
9
+
10
+ def easy_admin(options = {})
11
+ @options = options
12
+
13
+ make_resourceful do
14
+ actions :all
15
+
16
+ response_for :index do |format|
17
+ format.html do
18
+ @options = options
19
+ override = File.join('app/views', self.controller_path, 'index.html.erb')
20
+ if File.exists?(override)
21
+ render :template => override
22
+ else
23
+ render :template => 'easy_admin_ui/index'
24
+ end
25
+ end
26
+ end
27
+
28
+ response_for :show do |format|
29
+ format.html { redirect_to :action => 'index' }
30
+ end
31
+
32
+ [:new, :create_fails].each do |new_action|
33
+ response_for new_action do |format|
34
+ format.html do
35
+ override = File.join(controller_full_path, 'new.html.erb')
36
+ if File.exists?(override)
37
+ render :template => override
38
+ else
39
+ render :template => 'easy_admin_ui/new'
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ [:edit, :update_fails].each do |edit_action|
46
+ response_for edit_action do |format|
47
+ format.html do
48
+ override = File.join(controller_full_path, 'edit.html.erb')
49
+ if File.exists?(override)
50
+ render :template => override
51
+ else
52
+ render :template => 'easy_admin_ui/edit'
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ response_for :destroy do |format|
59
+ format.js do
60
+ render :update do |page|
61
+ page.remove "tr_#{current_model_name.underscore}_#{@item.id}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ class_eval do
68
+ def options
69
+ self.class.options
70
+ end
71
+
72
+ def current_objects
73
+ @items = current_model.paginate(:page => params[:page], :per_page => options[:per_page], :order => options[:order])
74
+ end
75
+
76
+ def current_object
77
+ @item ||= current_model.find(params[:id]) if params[:id]
78
+ @item ||= current_model.new(params[current_model_name.underscore.to_sym])
79
+ end
80
+
81
+ def instance_variable_name
82
+ 'item'
83
+ end
84
+
85
+ helper_method :controller_full_path
86
+ def controller_full_path
87
+ File.join 'app/views', self.controller_path
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,11 @@
1
+ # require 'easy_admin_ui/tasks' in your Rakefile.
2
+
3
+ namespace :easy_admin_ui do
4
+ desc "Copies assets to public/images/icons/"
5
+ task :copy_assets do
6
+ FileUtils.mkdir_p "#{RAILS_ROOT}/public/images/icons/"
7
+
8
+ Dir.chdir(File.dirname(__FILE__) + '/../assets/')
9
+ FileUtils.cp_r(Dir.glob('icons/*.*'), "#{RAILS_ROOT}/public/images/icons/", :verbose => true)
10
+ end
11
+ end
@@ -0,0 +1,86 @@
1
+ module EasyAdminUi
2
+ module ViewHelpers
3
+ def wpaginate(collection)
4
+ will_paginate(collection, :previous_label => t('will_paginate.previous'), :next_label => t('will_paginate.next'))
5
+ end
6
+
7
+ def table_head(titles, actions, options = {:class => "easy"})
8
+ concat("<table class='#{options[:class]}' id='#{options[:id]}'>" +
9
+ content_tag(:thead,
10
+ content_tag(:tr, (
11
+ titles.map do |title, th_class|
12
+ th_class ||= []
13
+ content_tag(:th,
14
+ [
15
+ if th_class.include?('sortable')
16
+ content_tag(:div,
17
+ link_to('', '#', :class => 'sort_up') +
18
+ link_to('', '#', :class => 'sort_down'),
19
+ :class => 'sort')
20
+ else
21
+ nil
22
+ end,
23
+ title
24
+ ].compact.join(''),
25
+ :class => th_class)
26
+ end
27
+ ).join('') + (actions ? content_tag(:th, '', :class => 'actions') : '')
28
+ )
29
+ )
30
+ )
31
+ options[:body_id] ? concat("<tbody id=\"#{options[:body_id]}\">") : concat('<tbody>')
32
+ yield
33
+ concat('</tbody></table>')
34
+ end
35
+
36
+ def table_row(options = {})
37
+ options[:actions] ||= []
38
+
39
+ content_tag(:tr,
40
+ [
41
+ # Could pass:
42
+ #
43
+ # [category.created_at, {:class => '', :onmouseover => "javascript: blah"}]
44
+ # [category.created_at, 'my_class_name']
45
+ #
46
+ options[:cells].map do |txt, cell_opts|
47
+ cell_opts = {:class => cell_opts} if cell_opts.is_a?(String)
48
+ cell_opts ||= {}
49
+ content_tag(:td, txt, cell_opts)
50
+ end,
51
+ options[:actions].blank? ? '' : content_tag(:td, options[:actions].join(' '), :class => "act")
52
+ ].join(' '),
53
+ :id => options[:id], :class => ["#{cyc = cycle("even", "odd")}", options[:class]].join(' '))
54
+ end
55
+
56
+ def right_align(content)
57
+ [content, 'aright']
58
+ end
59
+
60
+ def admin_show_link(item)
61
+ link_to(image_tag("/images/icons/show.png"), :action => 'show', :id => item)
62
+ end
63
+
64
+ def admin_new_link
65
+ content_tag(:span, ' - ' + link_to('New', :action => 'new'))
66
+ end
67
+
68
+ def admin_edit_link(item)
69
+ link_to(image_tag("/images/icons/pencil.png"), :action => 'edit', :id => item)
70
+ end
71
+
72
+ # Use if below /admin/.
73
+ def admin_delete_link_with_confirmation(obj, delete_path=nil)
74
+ delete_path ||= eval("admin_#{obj.class.to_s.underscore}_path(obj)")
75
+ delete_link_with_confirmation(obj, delete_path)
76
+ end
77
+
78
+ def delete_link_with_confirmation(obj, delete_path=nil)
79
+ delete_path ||= eval("#{obj.class.to_s.underscore.singularize}_path(obj)")
80
+ link_to_function(image_tag('/images/icons/delete.png'), "$('cnf_#{obj.id}').show();") + ' ' +
81
+ raw('<span id="cnf_' + obj.id.to_s + '" class="conf_link" style="display: none;">Are you sure? ') +
82
+ link_to_remote("Yes", :url => delete_path, :method => :delete) + ' ' +
83
+ link_to_function("No", "$('cnf_#{obj.id}').hide();") + raw('</span>')
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,12 @@
1
+ require 'easy_admin_ui/core_ext'
2
+ require 'easy_admin_ui/view_helpers'
3
+
4
+ ActionController::Base.view_paths = ["app/views", File.dirname(__FILE__) + "/../templates"]
5
+
6
+ ActionController::Base.class_eval do
7
+ include EasyAdminUi::CoreExt
8
+ end
9
+
10
+ ActionView::Base.class_eval do
11
+ include EasyAdminUi::ViewHelpers
12
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'easy_admin_ui/tasks'
@@ -0,0 +1,30 @@
1
+ <h1>Editing <%= @item.class.to_s.tableize.singularize.humanize %></h1>
2
+
3
+ <% if File.exists?(File.join(controller_full_path, '_modify_after_title.html.erb')) -%>
4
+ <%= render :partial => 'modify_after_title' %>
5
+ <% elsif File.exists?(File.join(controller_full_path, '_edit_after_title.html.erb')) -%>
6
+ <%= render :partial => 'edit_after_title' %>
7
+ <% end -%>
8
+
9
+ <% if File.exists?(File.join(controller_full_path, '_after_title.html.erb')) -%>
10
+ <%= render :partial => 'after_title' %>
11
+ <% end -%>
12
+
13
+ <% semantic_form_for(@item, :url => eval("admin_#{@item.class.to_s.underscore}_path(@item)"), :html => { :multipart => true }) do |f| %>
14
+ <% f.inputs do %>
15
+ <%= render :partial => 'form', :locals => {:f => f} %>
16
+ <% end -%>
17
+ <% f.buttons do %>
18
+ <%= f.commit_button 'Submit' %>
19
+ <% end -%>
20
+ <% end -%>
21
+
22
+ <% if File.exists?(File.join(controller_full_path, '_modify_after_form.html.erb')) -%>
23
+ <%= render :partial => 'modify_after_form' %>
24
+ <% elsif File.exists?(File.join(controller_full_path, '_edit_after_form.html.erb')) -%>
25
+ <%= render :partial => 'edit_after_form' %>
26
+ <% end -%>
27
+
28
+ <% if File.exists?(File.join(controller_full_path, '_after_form.html.erb')) -%>
29
+ <%= render :partial => 'after_form' %>
30
+ <% end -%>
@@ -0,0 +1,21 @@
1
+ <h1><%= @options[:page_title] %> <%= admin_new_link unless @options[:skip_new] %></h1>
2
+
3
+ <% if File.exists?(File.join(controller_full_path, '_index_after_title.html.erb')) -%>
4
+ <%= render :partial => 'index_after_title' %>
5
+ <% elsif File.exists?(File.join(controller_full_path, '_after_title.html.erb')) -%>
6
+ <%= render :partial => 'after_title' %>
7
+ <% end -%>
8
+
9
+ <%= wpaginate @items if @items.respond_to?(:total_pages) %>
10
+
11
+ <% table_head(@options[:columns], @options[:actions]) do %>
12
+ <%= render @items %>
13
+ <% end -%>
14
+
15
+ <%= wpaginate @items if @items.respond_to?(:total_pages) %>
16
+
17
+ <% if File.exists?(File.join(controller_full_path, '_index_after_table.html.erb')) -%>
18
+ <%= render :partial => 'index_after_table' %>
19
+ <% elsif File.exists?(File.join(controller_full_path, '_after_table.html.erb')) -%>
20
+ <%= render :partial => 'after_table' %>
21
+ <% end -%>
@@ -0,0 +1,30 @@
1
+ <h1>New <%= @item.class.to_s.tableize.singularize.humanize %></h1>
2
+
3
+ <% if File.exists?(File.join(controller_full_path, '_modify_after_title.html.erb')) -%>
4
+ <%= render :partial => 'modify_after_title' %>
5
+ <% elsif File.exists?(File.join(controller_full_path, '_new_after_title.html.erb')) -%>
6
+ <%= render :partial => 'new_after_title' %>
7
+ <% end -%>
8
+
9
+ <% if File.exists?(File.join(controller_full_path, '_after_title.html.erb')) -%>
10
+ <%= render :partial => 'after_title' %>
11
+ <% end -%>
12
+
13
+ <% semantic_form_for(@item, :url => eval("admin_#{@item.class.to_s.underscore.pluralize}_path"), :html => { :multipart => true }) do |f| %>
14
+ <% f.inputs do %>
15
+ <%= render :partial => 'form', :locals => {:f => f} %>
16
+ <% end -%>
17
+ <% f.buttons do %>
18
+ <%= f.commit_button 'Submit' %>
19
+ <% end -%>
20
+ <% end -%>
21
+
22
+ <% if File.exists?(File.join(controller_full_path, '_modify_after_form.html.erb')) -%>
23
+ <%= render :partial => 'modify_after_form' %>
24
+ <% elsif File.exists?(File.join(controller_full_path, '_new_after_form.html.erb')) -%>
25
+ <%= render :partial => 'new_after_form' %>
26
+ <% end -%>
27
+
28
+ <% if File.exists?(File.join(controller_full_path, '_after_form.html.erb')) -%>
29
+ <%= render :partial => 'after_form' %>
30
+ <% end -%>
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_admin_ui
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Martin Moen Wulffeld
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-27 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Very simple DRY admin UI.
22
+ email: martin@wulffeld.org
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - .gitignore
31
+ - README
32
+ - Rakefile
33
+ - VERSION
34
+ - assets/css/easy_admin_ui.css
35
+ - assets/icons/classify.png
36
+ - assets/icons/connect.png
37
+ - assets/icons/delete.png
38
+ - assets/icons/disconnect.png
39
+ - assets/icons/pencil.png
40
+ - assets/icons/show.png
41
+ - easy_admin_ui.gemspec
42
+ - lib/easy_admin_ui.rb
43
+ - lib/easy_admin_ui/core_ext.rb
44
+ - lib/easy_admin_ui/tasks.rb
45
+ - lib/easy_admin_ui/view_helpers.rb
46
+ - tasks/easy_admin_ui.rake
47
+ - templates/easy_admin_ui/edit.html.erb
48
+ - templates/easy_admin_ui/index.html.erb
49
+ - templates/easy_admin_ui/new.html.erb
50
+ has_rdoc: true
51
+ homepage: http://github.com/wulffeld/easy_admin_ui
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Easy Admin UI.
80
+ test_files: []
81
+