quirkey-qadmin 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,7 +9,8 @@ $hoe = Hoe.new('qadmin', Qadmin::VERSION) do |p|
9
9
  p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
10
  p.rubyforge_name = 'quirkey'
11
11
  p.extra_deps = [
12
- ['activesupport','>= 2.2.0']
12
+ ['activesupport','>= 2.2.0'],
13
+ ['restful_query','>= 0.1.0']
13
14
  ]
14
15
  p.extra_dev_deps = [
15
16
  ['newgem', ">= #{::Newgem::VERSION}"]
@@ -3,34 +3,36 @@ module Qadmin
3
3
 
4
4
  module Macros
5
5
 
6
+
6
7
  def qadmin(options = {})
8
+ extend ::Qadmin::Options
7
9
  self.cattr_accessor :model_name, :model_instance_name, :model_collection_name, :model_human_name, :available_actions
8
10
  self.available_actions = [:index, :show, :new, :create, :edit, :update, :destroy]
9
11
  self.available_actions = [options[:only]].flatten if options[:only]
10
12
  self.available_actions -= [options[:exclude]].flatten if options[:exclude]
11
- self.model_name = self.to_s.demodulize.gsub(/Controller/,'').singularize
12
- self.model_instance_name = model_name.underscore
13
- self.model_collection_name = model_instance_name.pluralize
14
- self.model_human_name = model_instance_name.humanize
15
- self.append_view_paths(File.join(File.dirname(__FILE__), 'views'))
13
+ self.extract_model_from_options(options)
14
+ self.append_view_path(File.join(File.dirname(__FILE__), 'views'))
15
+ include Qadmin::Templates
16
+ include Qadmin::Overlay
16
17
  define_admin_actions(available_actions, options)
17
18
  end
18
-
19
+
19
20
  private
21
+
20
22
  def define_admin_actions(actions, options = {})
21
23
  action_method_code = {
22
24
  :index => %{
23
25
  def index
24
- @#{model_collection_name} = #{model_name}.paginate(:page => (params[:page] || 1))
26
+ @model_collection = @#{model_collection_name} = #{model_name}.paginate(:page => (params[:page] || 1))
25
27
  respond_to do |format|
26
- format.html
28
+ format.html { render_template_for_section }
27
29
  format.xml
28
30
  end
29
31
  end
30
32
  },
31
33
  :show => %{
32
34
  def show
33
- @#{model_instance_name} = #{model_name}.find(params[:id])
35
+ @model_instance = @#{model_instance_name} = #{model_name}.find(params[:id])
34
36
  respond_to do |format|
35
37
  format.html
36
38
  format.xml
@@ -39,8 +41,7 @@ module Qadmin
39
41
  },
40
42
  :new => %{
41
43
  def new
42
- @#{model_instance_name} = #{model_name}.new
43
-
44
+ @model_instance = @#{model_instance_name} = #{model_name}.new
44
45
  respond_to do |format|
45
46
  format.html # new.html.erb
46
47
  format.xml { render :xml => @#{model_instance_name} }
@@ -49,7 +50,7 @@ module Qadmin
49
50
  },
50
51
  :create => %{
51
52
  def create
52
- @#{model_instance_name} = #{model_name}.new(params[:#{model_instance_name}])
53
+ @model_instance = @#{model_instance_name} = #{model_name}.new(params[:#{model_instance_name}])
53
54
  respond_to do |format|
54
55
  if @#{model_instance_name}.save
55
56
  flash[:message] = '#{model_human_name} was successfully created.'
@@ -64,12 +65,12 @@ module Qadmin
64
65
  },
65
66
  :edit => %{
66
67
  def edit
67
- @#{model_instance_name} = #{model_name}.find(params[:id])
68
+ @model_instance = @#{model_instance_name} = #{model_name}.find(params[:id])
68
69
  end
69
70
  },
70
71
  :update => %{
71
72
  def update
72
- @#{model_instance_name} = #{model_name}.find(params[:id])
73
+ @model_instance = @#{model_instance_name} = #{model_name}.find(params[:id])
73
74
 
74
75
  respond_to do |format|
75
76
  if @#{model_instance_name}.update_attributes(params[:#{model_instance_name}])
@@ -85,7 +86,7 @@ module Qadmin
85
86
  },
86
87
  :destroy => %{
87
88
  def destroy
88
- @#{model_instance_name} = #{model_name}.find(params[:id])
89
+ @model_instance = @#{model_instance_name} = #{model_name}.find(params[:id])
89
90
  @#{model_instance_name}.destroy
90
91
  flash[:message] = "#{model_human_name} \#{@#{model_instance_name}} was deleted"
91
92
  respond_to do |format|
@@ -96,26 +97,13 @@ module Qadmin
96
97
  }
97
98
  }
98
99
  action_code = actions.collect {|a| action_method_code[a.to_sym] }.join("\n")
100
+ helper_methods = %{
101
+ helper_method :model_name, :model_instance_name, :model_collection_name, :model_human_name, :model_klass, :available_actions
102
+ }
103
+ action_code = helper_methods << action_code
99
104
  self.class_eval(action_code)
100
105
  end
101
106
  end
102
107
 
103
-
104
- # GET /<%= controller_file_path %>/new
105
- # GET /<%= controller_file_path %>/new.xml
106
-
107
- # GET /<%= controller_file_path %>/1/edit
108
-
109
- # POST /<%= controller_file_path %>
110
- # POST /<%= controller_file_path %>.xml
111
-
112
- # PUT /<%= controller_file_path %>/1
113
- # PUT /<%= controller_file_path %>/1.xml
114
-
115
-
116
- # DELETE /<%= controller_file_path %>/1
117
- # DELETE /<%= controller_file_path %>/1.xml
118
-
119
-
120
108
  end
121
109
  end
data/lib/qadmin/helper.rb CHANGED
@@ -1,11 +1,12 @@
1
- module Qadmin
2
- module Helper
1
+ module Qadmin
2
+ module Helper
3
+ include ::Qadmin::Options
3
4
 
4
5
  def fieldset(legend = nil, options = {}, &block)
5
- content_tag(:fieldset, options) do
6
+ concat(content_tag_for(:fieldset, options) do
6
7
  content_tag(:legend, legend) if legend
7
- yield
8
- end
8
+ capture(&block)
9
+ end)
9
10
  end
10
11
 
11
12
  def admin_controls(name, options = {}, &block)
@@ -50,6 +51,43 @@ module Qadmin
50
51
  html
51
52
  end
52
53
  end
54
+
55
+ def sortable_column_header(attribute_name, options = {})
56
+
57
+ end
58
+
59
+
60
+ def admin_table(collection, options = {})
61
+ html = '<table>'
62
+ html << '<tr>'
63
+ attributes = options[:attributes] || model_klass.column_names
64
+ attributes.each_with_index do |attribute, i|
65
+ html << (i == 0 ? '<th class="first_col">' : '<th>')
66
+ html << sortable_column_header(attribute)
67
+ html << '</th>'
68
+ end
69
+ html << %{
70
+ <th>View</th>
71
+ <th>Edit</th>
72
+ <th>Delete</th>
73
+ </tr>
74
+ }
75
+ collection.each do |instance|
76
+ html << %{<tr id="#{dom_id(instance)}" #{alt_rows}>}
77
+ attributes.each_with_index do |attribute, i|
78
+ if i == 0
79
+ html << %{<td class="first_col">#{link_to(instance.send(attribute), send("#{model_instance_name}_path", instance))}</td>}
80
+ else
81
+ html << %{<td>#{h(instance.send(attribute))}</td>}
82
+ end
83
+ end
84
+ html << %{<td>#{link_to(image_tag('admin/icon_show.png'), send("#{model_instance_name}_path", instance))}</td>}
85
+ html << %{<td>#{link_to(image_tag('admin/icon_edit.png'), send("edit_#{model_instance_name}_path", instance))}</td>}
86
+ html << %{<td>#{link_to(image_tag('admin/icon_destroy.png'), send("#{model_instance_name}_path", instance), :confirm => 'Are you sure?', :method => :delete)}</td>}
87
+ html << '</tr>'
88
+ end
89
+ html << '</table>'
90
+ end
53
91
 
54
92
  def alt_rows
55
93
  %{class="#{cycle('alt', '')}"}
data/lib/qadmin.rb CHANGED
@@ -6,8 +6,13 @@ unless defined?(ActiveSupport)
6
6
  end
7
7
 
8
8
  module Qadmin
9
- VERSION = '0.1.0'
9
+ VERSION = '0.1.1'
10
10
  end
11
11
 
12
- require 'qadmin/helper'
13
- require 'qadmin/controller'
12
+ %w{
13
+ options
14
+ helper
15
+ overlay
16
+ templates
17
+ controller
18
+ }.each {|lib| require "qadmin/#{lib}" }
data/rails/init.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', 'qadmin/qadmin')
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'qadmin')
2
2
 
3
- ActionController::Base.send(:extend, Qadmin::Base)
3
+ ActionController::Base.send(:extend, Qadmin::Controller::Macros)
4
4
  ActionView::Base.send(:include, Qadmin::Helper)
@@ -39,10 +39,10 @@ class QadminGenerator < Rails::Generator::NamedBase
39
39
  m.directory(File.join('public','images','admin'))
40
40
 
41
41
  #copy form over too
42
- m.template("_form.html.erb",File.join('app','views', controller_class_path, controller_file_name, "_form.html.erb"))
42
+ m.template("_form.erb",File.join('app','views', controller_class_path, controller_file_name, "_form.erb"))
43
43
 
44
44
  # Layout and stylesheet.
45
- m.template('layout.html.erb', File.join('app','views','layouts', "admin.html.erb"))
45
+ m.template('layout.erb', File.join('app','views','layouts', "admin.erb"))
46
46
  m.template('style.css', 'public/stylesheets/admin.css')
47
47
 
48
48
  m.template(
data/test/test_helper.rb CHANGED
@@ -4,6 +4,9 @@ require 'test/unit'
4
4
  require 'mocha'
5
5
  require 'shoulda'
6
6
 
7
+ require File.dirname(__FILE__) + '/../lib/qadmin'
8
+
9
+
7
10
  # mock AR::BASE
8
11
  module ActiveRecord
9
12
  class Base
@@ -19,7 +22,6 @@ module ActiveRecord
19
22
  end
20
23
  end
21
24
 
22
- require File.dirname(__FILE__) + '/../lib/qadmin'
23
25
 
24
26
 
25
27
  class MockColumn
@@ -62,7 +64,10 @@ end
62
64
 
63
65
  class MockController
64
66
  class << self
65
- def append_view_paths(paths)
67
+ def append_view_path(paths)
68
+ end
69
+
70
+ def helper_method(*args)
66
71
  end
67
72
  end
68
73
 
@@ -26,8 +26,8 @@ class TestQadminGenerator < Test::Unit::TestCase
26
26
  end
27
27
  assert_generated_class('test/functional/items_controller_test')
28
28
  assert_directory_exists('app/views/items')
29
- assert_generated_file('app/views/items/_form.html.erb')
30
- assert_generated_file('app/views/layouts/admin.html.erb')
29
+ assert_generated_file('app/views/items/_form.erb')
30
+ assert_generated_file('app/views/layouts/admin.erb')
31
31
  assert_directory_exists('public/images/admin/')
32
32
  end
33
33
 
@@ -44,7 +44,7 @@ class TestQadminGenerator < Test::Unit::TestCase
44
44
  def base_files
45
45
  [
46
46
  'public/stylesheets/style.css',
47
- 'app/views/layouts/main.html.erb',
47
+ 'app/views/layouts/main.erb',
48
48
  'config/routes.rb'
49
49
  ]
50
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quirkey-qadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Quint
@@ -1,12 +0,0 @@
1
- <h2>Editing <%= singular_name.humanize.capitalize %></h2>
2
-
3
- <%%= admin_controls :<%= table_name %>, :for => :edit, :object => @<%= singular_name %> %>
4
-
5
- <%%= error_messages_for :<%= singular_name %> %>
6
-
7
- <%% form_for(@<%= singular_name %>) do |f| %>
8
- <%%= render :partial => 'form', :locals => {:f => f, :<%= singular_name %> => @<%= singular_name %>} %>
9
- <p><%%= f.submit "Update" %></p>
10
- <%% end %>
11
-
12
- <%%= admin_controls :<%= table_name %>, :for => :edit, :object => @<%= singular_name %> %>
@@ -1,31 +0,0 @@
1
- <h2><%= plural_name.humanize.capitalize %></h2>
2
-
3
- <%%= admin_controls :<%= table_name %>, :for => :index %>
4
-
5
- <%%= will_paginate(@<%= plural_name %>) %>
6
- <table>
7
- <tr>
8
- <% attributes.each_with_index do |attribute, i| -%>
9
- <th<% if i == 0 -%> class="first_col"<% end -%>><%%= sorterable_link :<%= attribute.name -%> %></th>
10
- <% end -%>
11
- <th>View</th>
12
- <th>Edit</th>
13
- <th>Delete</th>
14
- </tr>
15
-
16
- <%% @<%= plural_name %>.each do |<%= singular_name %>| %>
17
- <tr id="<%%= dom_id(<%= singular_name %>) %>" <%%= alt_rows %>>
18
- <% attributes.each_with_index do |attribute, i| -%>
19
- <% if i == 0 -%><td class="first_col"><%%= link_to <%= singular_name %>.<%= attribute.name %>, <%= table_name.singularize %>_path(<%= singular_name %>) %></td><%- else -%>
20
- <td><%%= h <%= singular_name %>.<%= attribute.name %> %></td>
21
- <%- end -%>
22
- <% end -%>
23
- <td><%%= link_to image_tag('admin/icon_show.png'), <%= table_name.singularize %>_path(<%= singular_name %>) %></td>
24
- <td><%%= link_to image_tag('admin/icon_edit.png'), edit_<%= table_name.singularize %>_path(<%= singular_name %>) %></td>
25
- <td><%%= link_to image_tag('admin/icon_destroy.png'), <%= table_name.singularize %>_path(<%= singular_name %>), :confirm => 'Are you sure?', :method => :delete %></td>
26
- </tr>
27
- <%% end %>
28
- </table>
29
- <%%= will_paginate(@<%= plural_name %>) %>
30
-
31
- <%%= admin_controls :<%= table_name %>, :for => :index %>
@@ -1,12 +0,0 @@
1
- <h2><%= singular_name.humanize.capitalize %>: New</h2>
2
-
3
- <%%= admin_controls :<%= table_name %>, :for => :new %>
4
-
5
- <%%= error_messages_for :<%= singular_name %> %>
6
-
7
- <%% form_for(@<%= singular_name %>) do |f| %>
8
- <%%= render :partial => 'form', :locals => {:f => f, :<%= singular_name %> => @<%= singular_name %>} %>
9
- <p><%%= f.submit "Create" %></p>
10
- <%% end %>
11
-
12
- <%%= admin_controls :<%= table_name %>, :for => :new %>
@@ -1,14 +0,0 @@
1
- <h2><%= plural_name.humanize.capitalize %>: <%%= @<%= singular_name %>.to_s %></h2>
2
-
3
- <%%= admin_controls :<%= table_name %>, :for => :show, :object => @<%= singular_name %> %>
4
-
5
- <div id="<%%= dom_id(@<%= singular_name %>) %>">
6
- <div class="fields_group">
7
- <% attributes.each do |attribute| -%>
8
- <h5><%= attribute.human_name %>:</h5>
9
- <%%=h @<%= singular_name %>.<%= attribute.name %> %>
10
- <% end -%>
11
- </div>
12
- </div>
13
-
14
- <%%= admin_controls :<%= table_name %>, :for => :show, :object => @<%= singular_name %> %>
@@ -1,7 +0,0 @@
1
- <%% fieldset do %>
2
- <% attributes.each do |attribute| -%>
3
- <% unless ignore_attributes.include?(attribute.name) -%>
4
- <p><label><%= attribute.human_name %></label><%%= f.text_field :<%= attribute.name %> %></p>
5
- <% end -%>
6
- <% end -%>
7
- <%% end %>
@@ -1,45 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
-
4
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
- <head>
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
-
8
- <title>Admin</title>
9
-
10
- <%%= stylesheet_link_tag 'admin' %>
11
- <%%= javascript_include_tag :defaults %>
12
- <%%= javascript_include_tag 'file_browser' %>
13
- </head>
14
- <body>
15
- <div id="header">
16
- <h1>Admin</h1>
17
- <div id="loginbox"><%% if logged_in? %>Welcome, <%%= current_user %> / <%%= link_to "Logout", '/logout' %><%% else %><%%= link_to "Login", '/login' %><%% end %></div>
18
- </div>
19
- <div id="main">
20
- <div id="left_menu">
21
- <h3>Panels</h3>
22
- <ul class="menu">
23
- <%% simple_menu([]) do |name,controller| %>
24
- <li><%%= link_to(name.titleize, {:controller => controller}, :class => (like_current_page?(:controller => controller) ? 'selected' : '')) %></li>
25
- <%% end %>
26
- </ul>
27
- <h3>Quick Links</h3>
28
- <ul class="menu">
29
- </ul>
30
- </div>
31
- <div id="content">
32
- <%% if flash[:message] %>
33
- <div id="message_main" class="message">
34
- <%%= h flash[:message] %>
35
- </div>
36
- <%% elsif flash[:warning] %>
37
- <div id="message_main" class="message warning">
38
- <%%= h flash[:warning] %>
39
- </div>
40
- <%% end %>
41
- <%%= yield %>
42
- </div>
43
- </div>
44
- </body>
45
- </html>