sunrise-scaffold 0.1.0

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.
Files changed (28) hide show
  1. data/README.rdoc +8 -0
  2. data/Rakefile +44 -0
  3. data/lib/generators/sunrise_scaffold/USAGE +6 -0
  4. data/lib/generators/sunrise_scaffold/manage_generator.rb +112 -0
  5. data/lib/generators/sunrise_scaffold/templates/multiplay/controller.rb +36 -0
  6. data/lib/generators/sunrise_scaffold/templates/multiplay/functional_test.rb +103 -0
  7. data/lib/generators/sunrise_scaffold/templates/multiplay/helper.rb +2 -0
  8. data/lib/generators/sunrise_scaffold/templates/multiplay/views/edit.html.erb +6 -0
  9. data/lib/generators/sunrise_scaffold/templates/multiplay/views/form.html.erb +29 -0
  10. data/lib/generators/sunrise_scaffold/templates/multiplay/views/index.html.erb +32 -0
  11. data/lib/generators/sunrise_scaffold/templates/multiplay/views/item.html.erb +27 -0
  12. data/lib/generators/sunrise_scaffold/templates/multiplay/views/model_filter.html.erb +31 -0
  13. data/lib/generators/sunrise_scaffold/templates/multiplay/views/new.html.erb +6 -0
  14. data/lib/generators/sunrise_scaffold/templates/multiplay/views/show.html.erb +17 -0
  15. data/lib/generators/sunrise_scaffold/templates/single/controller.rb +31 -0
  16. data/lib/generators/sunrise_scaffold/templates/single/functional_test.rb +98 -0
  17. data/lib/generators/sunrise_scaffold/templates/single/helper.rb +2 -0
  18. data/lib/generators/sunrise_scaffold/templates/single/views/edit.html.erb +6 -0
  19. data/lib/generators/sunrise_scaffold/templates/single/views/form.html.erb +29 -0
  20. data/lib/generators/sunrise_scaffold/templates/single/views/index.html.erb +30 -0
  21. data/lib/generators/sunrise_scaffold/templates/single/views/item.html.erb +27 -0
  22. data/lib/generators/sunrise_scaffold/templates/single/views/model_filter.html.erb +31 -0
  23. data/lib/generators/sunrise_scaffold/templates/single/views/new.html.erb +6 -0
  24. data/lib/generators/sunrise_scaffold/templates/single/views/show.html.erb +17 -0
  25. data/lib/sunrise_scaffold.rb +5 -0
  26. data/lib/sunrise_scaffold/utils.rb +46 -0
  27. data/lib/sunrise_scaffold/version.rb +4 -0
  28. metadata +94 -0
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = SunRise CMS scaffold
2
+
3
+ == USAGE
4
+
5
+ # before this, you must generate model (rails g model model_name) and create it in db (rake db:migrate)
6
+ rails generate sunrise_scaffold:manage model_name
7
+
8
+ rails generate sunrise_scaffold:manage model_name --parent=parent_model
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require File.join(File.dirname(__FILE__), 'lib', 'sunrise_scaffold', 'version')
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'Test the sunrise plugin.'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ desc 'Generate documentation for the sunrise plugin.'
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'Sunrise Scaffold'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ begin
28
+ require 'jeweler'
29
+ Jeweler::Tasks.new do |s|
30
+ s.name = "sunrise-scaffold"
31
+ s.version = SunriseScaffold::VERSION.dup
32
+ s.summary = "Rails CMS"
33
+ s.description = "Sunrise is a Aimbulance CMS"
34
+ s.email = "galeta.igor@gmail.com"
35
+ s.homepage = "https://github.com/galetahub/sunrise-scaffold"
36
+ s.authors = ["Igor Galeta", "Pavlo Galeta"]
37
+ s.files = FileList["[A-Z]*", "lib/**/*"]
38
+ s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
39
+ end
40
+
41
+ Jeweler::GemcutterTasks.new
42
+ rescue LoadError
43
+ puts "Jeweler not available. Install it with: gem install jeweler"
44
+ end
@@ -0,0 +1,6 @@
1
+ Manage
2
+ ==============
3
+
4
+ rails generate sunrise_scaffold:manage ModelName
5
+
6
+ rails generate sunrise_scaffold:manage ModelName --parent=ParentModel
@@ -0,0 +1,112 @@
1
+ require 'rails/generators'
2
+ require 'sunrise_scaffold/utils'
3
+
4
+ module SunriseScaffold
5
+ class ManageGenerator < Rails::Generators::NamedBase
6
+ check_class_collision :suffix => "Controller"
7
+
8
+ class_option :parent, :type => :string, :default => nil,
9
+ :desc => "Parent model"
10
+
11
+ def self.source_root
12
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), "/templates"))
13
+ end
14
+
15
+ def create_controller_files
16
+ template "#{generator_dir}/controller.rb",
17
+ File.join('app/controllers', manage_path, "#{controller_file_name}_controller.rb")
18
+
19
+ template "#{generator_dir}/helper.rb",
20
+ File.join('app/helpers', manage_path, "#{controller_file_name}_helper.rb")
21
+ end
22
+
23
+ def create_tests_files
24
+ template "#{generator_dir}/functional_test.rb",
25
+ File.join('test/functional', manage_path, "#{controller_file_name}_controller_test.rb")
26
+ end
27
+
28
+ def create_views_files
29
+ # model form
30
+ template "#{generator_dir}/views/form.html.erb",
31
+ File.join('app/views', manage_path, controller_file_name, "_form.html.erb")
32
+
33
+ # search filter
34
+ template "#{generator_dir}/views/model_filter.html.erb",
35
+ File.join('app/views', manage_path, controller_file_name, "_model_filter.html.erb")
36
+
37
+ # collection view partial
38
+ template "#{generator_dir}/views/item.html.erb",
39
+ File.join('app/views', manage_path, controller_file_name, "_#{singular_name}.html.erb")
40
+
41
+ # other templates
42
+ [:index, :new, :edit, :show].each do |action|
43
+ template "#{generator_dir}/views/#{action}.html.erb",
44
+ File.join('app/views', manage_path, controller_file_name, "#{action}.html.erb")
45
+ end
46
+ end
47
+
48
+ protected
49
+
50
+ def manage_path
51
+ "manage"
52
+ end
53
+
54
+ def klass
55
+ # First priority is the namespaced modek, e.g. User::Group
56
+ @klass ||= begin
57
+ namespaced_class = name.singularize
58
+ namespaced_class.constantize
59
+ rescue NameError
60
+ nil
61
+ end
62
+
63
+ # Second priority the camelcased c, i.e. UserGroup
64
+ @klass ||= begin
65
+ camelcased_class = name.gsub('::', '').singularize
66
+ camelcased_class.constantize
67
+ rescue NameError
68
+ nil
69
+ end
70
+
71
+ @klass ||= model_name.constantize
72
+
73
+ @klass
74
+ end
75
+
76
+ def model
77
+ @model ||= klass.new
78
+ end
79
+
80
+ def model_name
81
+ @model_name ||= name.camelize
82
+ @model_name
83
+ end
84
+
85
+ def controller_class_name
86
+ @controller_class_name ||= name.pluralize.camelize
87
+ end
88
+
89
+ def controller_file_name
90
+ @controller_file_name ||= file_name.pluralize
91
+ end
92
+
93
+ def generator_dir
94
+ options[:parent] ? "multiplay" : "single"
95
+ end
96
+
97
+ def parent_class_name
98
+ @parent_class_name ||= parent_singular_name.camelize
99
+ @parent_class_name
100
+ end
101
+
102
+ def parent_singular_name
103
+ @parent_singular_name ||= options[:parent].singularize
104
+ @parent_singular_name
105
+ end
106
+
107
+ def translated_columns
108
+ @translated_columns ||= klass.translated_attribute_names if klass.respond_to?(:translated_attribute_names)
109
+ @translated_columns ||= []
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,36 @@
1
+ class Manage::<%= controller_class_name %>Controller < Manage::BaseController
2
+ inherit_resources
3
+ defaults :route_prefix => 'manage'
4
+ belongs_to :<%= parent_singular_name %>
5
+
6
+ before_filter :make_filter, :only=>[:index]
7
+
8
+ load_and_authorize_resource :<%= singular_name %>, :through => :<%= parent_singular_name %>
9
+
10
+ def create
11
+ create!{ manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id) }
12
+ end
13
+
14
+ def update
15
+ update!{ manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id) }
16
+ end
17
+
18
+ def destroy
19
+ destroy!{ manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id) }
20
+ end
21
+
22
+ protected
23
+
24
+ def begin_of_association_chain
25
+ @<%= parent_singular_name %>
26
+ end
27
+
28
+ def collection
29
+ @<%= plural_name %> = (@<%= plural_name %> || end_of_association_chain).merge(@search.scoped).page(params[:page])
30
+ end
31
+
32
+ def make_filter
33
+ @search = Sunrise::ModelFilter.new(<%= model_name %>, :attributes=>[ <%= model.attributes.keys.map{ |a| ":#{a}" }.join(', ') %> ] )
34
+ @search.update_attributes(params[:search])
35
+ end
36
+ end
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+
3
+ class Manage::<%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ @admin = users(:admin)
7
+ @<%= parent_singular_name %> = <%= parent_class_name %>.find(:first)
8
+ end
9
+
10
+ test "index" do
11
+ get :index, {:<%= parent_singular_name %>_id => @<%= parent_singular_name %>.id }, {:user_id=>@admin.id}
12
+
13
+ assert_response :success
14
+ assert_not_nil assigns(:<%= plural_name %>)
15
+ end
16
+
17
+ test "new" do
18
+ get :new, {:<%= parent_singular_name %>_id => @<%= parent_singular_name %>.id }, {:user_id=>@admin.id}
19
+
20
+ assert_response :success
21
+ assert_not_nil assigns(:<%= singular_name %>)
22
+ assert assigns(:<%= singular_name %>).new_record?
23
+ end
24
+
25
+ test "should_create_<%= singular_name %>" do
26
+ assert_difference('<%= model_name %>.count') do
27
+ post :create, {:<%= singular_name %> => { :title => '<%= model_name %> test title'},
28
+ :<%= parent_singular_name %>_id => @<%= parent_singular_name %>.id},
29
+ {:user_id=>@admin.id}
30
+ end
31
+
32
+ assert assigns(:<%= singular_name %>).valid?
33
+ assert_equal assigns(:<%= singular_name %>).title, '<%= model_name %> test title'
34
+
35
+ assert_redirected_to manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id)
36
+ end
37
+
38
+ test "should_error_create_<%= singular_name %>" do
39
+ assert_no_difference('<%= model_name %>.count') do
40
+ post :create, {:<%= singular_name %> => { :title => nil},
41
+ :<%= parent_singular_name %>_id => @<%= parent_singular_name %>.id },
42
+ {:user_id=>@admin.id}
43
+ end
44
+
45
+ assert !assigns(:<%= singular_name %>).valid?
46
+ assert !assigns(:<%= singular_name %>).errors.empty?
47
+ assert assigns(:<%= singular_name %>).errors.on(:title)
48
+
49
+ assert_response :success
50
+ end
51
+
52
+ test "should_update_<%= singular_name %>" do
53
+ <%= singular_name %> = <%= model_name %>.create(:title=>'<%= model_name %> test title')
54
+
55
+ assert_no_difference('<%= model_name %>.count') do
56
+ put :update, {:id=><%= singular_name %>.id, :<%= singular_name %> => {
57
+ :title => '<%= model_name %> test title updated'},
58
+ :<%= parent_singular_name %>_id => @<%= parent_singular_name %>.id },
59
+ {:user_id=>@admin.id}
60
+ end
61
+
62
+ assert assigns(:<%= singular_name %>).valid?
63
+ assert_equal assigns(:<%= singular_name %>).title, '<%= model_name %> test title updated'
64
+
65
+ assert_redirected_to manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id)
66
+ end
67
+
68
+ test "should_error_update_<%= singular_name %>" do
69
+ <%= singular_name %> = <%= model_name %>.create(:title=>'<%= model_name %> test title')
70
+
71
+ assert_no_difference('<%= model_name %>.count') do
72
+ put :update, {:id=><%= singular_name %>.id, :<%= singular_name %> => { :title =>nil},
73
+ :<%= parent_singular_name %>_id => @<%= parent_singular_name %>.id },
74
+ {:user_id=>@admin.id}
75
+ end
76
+
77
+ assert !assigns(:<%= singular_name %>).valid?
78
+ assert !assigns(:<%= singular_name %>).errors.empty?
79
+ assert assigns(:<%= singular_name %>).errors.on(:title)
80
+
81
+ assert_response :success
82
+ end
83
+
84
+ test "should_destroy_<%= singular_name %>" do
85
+ <%= singular_name %> = <%= model_name %>.create(:title=>'<%= model_name %> test title')
86
+
87
+ assert_difference('<%= model_name %>.count', -1) do
88
+ delete :destroy, {:id=><%= singular_name %>.id, :<%= parent_singular_name %>_id => @<%= parent_singular_name %>.id }, {:user_id=>@admin.id}
89
+ end
90
+
91
+ assert_redirected_to manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id)
92
+
93
+ assert_raise(ActiveRecord::RecordNotFound) {
94
+ <%= model_name %>.find(<%= singular_name %>.id)
95
+ }
96
+ end
97
+
98
+ test "should_redirect_to_login" do
99
+ get :index
100
+
101
+ assert_redirected_to login_path
102
+ end
103
+ end
@@ -0,0 +1,2 @@
1
+ module Manage::<%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%%= t('manage.edit') %>:</div>
4
+ <%%= render :partial => 'manage/<%= plural_name %>/form' %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,29 @@
1
+ <%%= manage_form_for [@<%= parent_singular_name %>, @<%= singular_name %>] do |f| %>
2
+
3
+ <% unless translated_columns.empty? -%>
4
+ <%%= render(:partial=>"manage/shared/locale") %>
5
+
6
+ <%% Sunrise.available_locales.each do |locale|%>
7
+ <%%= content_tag :div, :id=>"s#{locale}_block", :class=>"add-white-bl", :style=>(I18n.locale.to_s == locale.to_s ? nil : 'display:none;') do %>
8
+ <div class="bot-bg">
9
+ <div class="inputs-bl">
10
+ <% translated_columns.each do |attribute| -%>
11
+ <%%= f.input :<%= attribute%>, :locale => locale %>
12
+ <% end -%>
13
+ </div>
14
+ </div>
15
+ <%% end -%>
16
+ <%% end -%>
17
+ <% end -%>
18
+
19
+ <div class="edit-cont">
20
+ <div class="inputs-bl">
21
+ <% model.attributes.each do |attribute, value| -%>
22
+ <% next if translated_columns.include?(attribute.to_sym) %>
23
+ <%%= f.input :<%= attribute%> %>
24
+ <% end -%>
25
+ </div>
26
+ </div>
27
+
28
+ <%%= f.button :submit, :url => manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id) %>
29
+ <%% end %>
@@ -0,0 +1,32 @@
1
+ <div class="duo-bl">
2
+ <div class="left-part">
3
+ <div class="content">
4
+ <div class="row-container">
5
+ <div class="white-row">
6
+ <div class="r-corn">
7
+ <%%= link_to t('manage.menu.<%= plural_name %>'), manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id), :class=>"dark-text" %>
8
+ <div class="act-bl">
9
+ <%%= link_to t('manage.add'), new_manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id), :class=>"create" %>
10
+ </div>
11
+ </div>
12
+ </div>
13
+ </div>
14
+ <div id="<%= plural_name %>" class="stage">
15
+ <%%= render :partial=>"manage/<%= plural_name %>/<%= singular_name %>", :collection=>@<%= plural_name %> %>
16
+ <%%= paginate @<%= plural_name %> %>
17
+ </div>
18
+
19
+ <script type='text/javascript'>
20
+ $(document).ready(function(){
21
+ Manage.init_collection('<%= plural_name %>', 'dinamic-bl');
22
+ });
23
+ </script>
24
+ </div>
25
+ </div>
26
+
27
+ <div class="right-part">
28
+ <div class="filter-right">
29
+ <%%= render :partial=>"manage/<%= plural_name %>/model_filter" %>
30
+ </div>
31
+ </div>
32
+ </div>
@@ -0,0 +1,27 @@
1
+ <%%= content_tag(:div, :id=>dom_id(<%= singular_name %>), :class=>"dinamic-bl") do %>
2
+ <div class="act-bl" style="display:none;">
3
+ <%%= link_to image_tag("manage/ico_edit.gif", :alt=>t('manage.edit'), :title=>t('manage.edit')), edit_manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id, <%= singular_name %>.id), :class=>"icons" %>
4
+
5
+ <%%= link_to image_tag("manage/ico_del.gif", :alt=>t('manage.delete'), :title=>t('manage.delete')), manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id, <%= singular_name %>.id),
6
+ :method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
7
+ </div>
8
+
9
+ <div class="bot-bg">
10
+ <div class="dinamic-container">
11
+ <div class="right-data">
12
+ <div class="right-data-cont">
13
+ <div class="dinamic-inner">
14
+ <div class="r-block">
15
+ <div class="r-block-cont">
16
+ <%%= link_to <%= singular_name %>.title, edit_manage_<%= parent_singular_name %>_<%= singular_name %>_path(@<%= parent_singular_name %>.id, <%= singular_name %>.id), :class=>"title" %>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ <div class="left-data">
23
+ <span class="data"><%%= raw I18n.l(<%= singular_name %>.created_at, :format=>"<span>%d/%m</span>%Y") %></span>
24
+ </div>
25
+ </div>
26
+ </div>
27
+ <%% end %>
@@ -0,0 +1,31 @@
1
+ <div class="bot-bg">
2
+ <div class="filt-bl">
3
+ <%%= link_to_function t('manage.model_filter.title'), "Manage.toggle_element('block_filter')", :class=>"dark-arr" %>
4
+
5
+ <%%= cookie_content_tag(:div, :id=>"block_filter", :class=>"filt") do %>
6
+ <%%= form_for @search, :as => :search, :url=>manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id), :html=>{:method=>:get, :id=>"form_filter"} do |f| %>
7
+ <% model.attributes.each do |attribute, value| -%>
8
+ <%%= f.label :<%= attribute %>, t('activerecord.attributes.<%= singular_name %>.<%= attribute %>') %>
9
+ <%%= f.text_field :<%= attribute %>, :class=>"text" %>
10
+ <% end -%>
11
+
12
+ <div class="buts">
13
+ <%%= f.submit t('manage.model_filter.search'), :style=>"display:none;" %>
14
+ <%%= link_to_function content_tag(:span, t('manage.model_filter.search')), "$('#form_filter').submit()", :class=>"gr" %>
15
+ <%%= link_to t('manage.model_filter.clear'), manage_<%= parent_singular_name %>_<%= plural_name %>_path(@<%= parent_singular_name %>.id), :class=>"erase" %>
16
+ </div>
17
+ <%% end %>
18
+ <%% end %>
19
+ </div>
20
+ <div class="sort">
21
+ <label><%%= t('manage.sort') %></label>
22
+ <div class="select-input"><%%= link_to_function t("<%= plural_name %>.#{@search.order_column}_#{@search.order_type}", :scope => [:manage, :sort_columns], :default => :"#{@search.order_column}_#{@search.order_type}"), "SelectList.toggle(event)", :class=>"corn", :id=>'sort_select' %></div>
23
+ <div id='sort_select_list' class="select-list" style='display:none;'>
24
+ <% model.attributes.each do |attribute, value| -%>
25
+ <%%= link_to_sort(t('<%= plural_name %>.<%= attribute %>_desc', :scope => [:manage, :sort_columns], :default => :<%= attribute %>_desc), :name => <%= attribute.inspect %>, :order_type => 'desc') %>
26
+ <%%= link_to_sort(t('<%= plural_name %>.<%= attribute %>_asc', :scope => [:manage, :sort_columns], :default => :<%= attribute %>_asc), :name => <%= attribute.inspect %>, :order_type => 'asc') %>
27
+ <% end %>
28
+ </div>
29
+ </div>
30
+
31
+ </div>
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%%= t('manage.add') %>:</div>
4
+ <%%= render :partial => 'manage/<%= plural_name %>/form' %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,17 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%%= @<%= singular_name %>.name %>:</div>
4
+ <div class="edit-cont">
5
+ <table border="0" cellspacing="0" cellpadding="0" class="page-info">
6
+ <tbody>
7
+ <%% @<%= singular_name %>.attributes.each do |attribute, value| %>
8
+ <tr>
9
+ <td><strong><%%= attribute %></strong></td>
10
+ <td><%%= value %></td>
11
+ </tr>
12
+ <%% end %>
13
+ </tbody>
14
+ </table>
15
+ </div>
16
+ </div>
17
+ </div>
@@ -0,0 +1,31 @@
1
+ class Manage::<%= controller_class_name %>Controller < Manage::BaseController
2
+ inherit_resources
3
+ defaults :route_prefix => 'manage'
4
+
5
+ before_filter :make_filter, :only=>[:index]
6
+
7
+ load_and_authorize_resource :class => <%= class_name %>
8
+
9
+ def create
10
+ create!{ manage_<%= plural_name %>_path }
11
+ end
12
+
13
+ def update
14
+ update!{ manage_<%= plural_name %>_path }
15
+ end
16
+
17
+ def destroy
18
+ destroy!{ manage_<%= plural_name %>_path }
19
+ end
20
+
21
+ protected
22
+
23
+ def collection
24
+ @<%= plural_name %> = (@<%= plural_name %> || end_of_association_chain).merge(@search.scoped).page(params[:page])
25
+ end
26
+
27
+ def make_filter
28
+ @search = Sunrise::ModelFilter.new(<%= class_name %>, :attributes=>[ <%= model.attributes.keys.map{ |a| ":#{a}" }.join(', ') %> ] )
29
+ @search.update_attributes(params[:search])
30
+ end
31
+ end
@@ -0,0 +1,98 @@
1
+ require 'test_helper'
2
+
3
+ class Manage::<%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ @admin = users(:admin)
7
+ end
8
+
9
+ test "index" do
10
+ get :index, nil, {:user_id=>@admin.id}
11
+
12
+ assert_response :success
13
+ assert_not_nil assigns(:<%= plural_name %>)
14
+ end
15
+
16
+ test "new" do
17
+ get :new, nil, {:user_id=>@admin.id}
18
+
19
+ assert_response :success
20
+ assert_not_nil assigns(:<%= singular_name %>)
21
+ assert assigns(:<%= singular_name %>).new_record?
22
+ end
23
+
24
+ test "should_create_<%= singular_name %>" do
25
+ assert_difference('<%= model_name %>.count') do
26
+ post :create, {:<%= singular_name %> => { :title => '<%= model_name %> test title'} },
27
+ {:user_id=>@admin.id}
28
+ end
29
+
30
+ assert assigns(:<%= singular_name %>).valid?
31
+ assert_equal assigns(:<%= singular_name %>).title, '<%= model_name %> test title'
32
+
33
+ assert_redirected_to manage_<%= plural_name %>_path
34
+ end
35
+
36
+ test "should_error_create_<%= singular_name %>" do
37
+ assert_no_difference('<%= model_name %>.count') do
38
+ post :create, {:<%= singular_name %> => { :title => nil} },
39
+ {:user_id=>@admin.id}
40
+ end
41
+
42
+ assert !assigns(:<%= singular_name %>).valid?
43
+ assert !assigns(:<%= singular_name %>).errors.empty?
44
+ assert assigns(:<%= singular_name %>).errors.on(:title)
45
+
46
+ assert_response :success
47
+ end
48
+
49
+ test "should_update_<%= singular_name %>" do
50
+ <%= singular_name %> = <%= model_name %>.create(:title=>'<%= model_name %> test title')
51
+
52
+ assert_no_difference('<%= model_name %>.count') do
53
+ put :update, {:id=><%= singular_name %>.id, :<%= singular_name %> => {
54
+ :title => '<%= model_name %> test title updated'} },
55
+ {:user_id=>@admin.id}
56
+ end
57
+
58
+ assert assigns(:<%= singular_name %>).valid?
59
+ assert_equal assigns(:<%= singular_name %>).title, '<%= model_name %> test title updated'
60
+
61
+ assert_redirected_to manage_<%= plural_name %>_path
62
+ end
63
+
64
+ test "should_error_update_<%= singular_name %>" do
65
+ <%= singular_name %> = <%= model_name %>.create(:title=>'<%= model_name %> test title')
66
+
67
+ assert_no_difference('<%= model_name %>.count') do
68
+ put :update, {:id=><%= singular_name %>.id, :<%= singular_name %> => { :title =>nil} },
69
+ {:user_id=>@admin.id}
70
+ end
71
+
72
+ assert !assigns(:<%= singular_name %>).valid?
73
+ assert !assigns(:<%= singular_name %>).errors.empty?
74
+ assert assigns(:<%= singular_name %>).errors.on(:title)
75
+
76
+ assert_response :success
77
+ end
78
+
79
+ test "should_destroy_<%= singular_name %>" do
80
+ <%= singular_name %> = <%= model_name %>.create(:title=>'<%= model_name %> test title')
81
+
82
+ assert_difference('<%= model_name %>.count', -1) do
83
+ delete :destroy, {:id=><%= singular_name %>.id}, {:user_id=>@admin.id}
84
+ end
85
+
86
+ assert_redirected_to manage_<%= plural_name %>_path
87
+
88
+ assert_raise(ActiveRecord::RecordNotFound) {
89
+ <%= model_name %>.find(<%= singular_name %>.id)
90
+ }
91
+ end
92
+
93
+ test "should_redirect_to_login" do
94
+ get :index
95
+
96
+ assert_redirected_to login_path
97
+ end
98
+ end
@@ -0,0 +1,2 @@
1
+ module Manage::<%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%%= t('manage.edit') %>:</div>
4
+ <%%= render :partial => 'manage/<%= plural_name %>/form' %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,29 @@
1
+ <%%= manage_form_for @<%= singular_name %> do |f| %>
2
+
3
+ <% unless translated_columns.empty? -%>
4
+ <%%= render(:partial=>"manage/shared/locale") %>
5
+
6
+ <%% Sunrise.available_locales.each do |locale|%>
7
+ <%%= content_tag :div, :id=>"s#{locale}_block", :class=>"add-white-bl", :style=>(I18n.locale.to_s == locale.to_s ? nil : 'display:none;') do %>
8
+ <div class="bot-bg">
9
+ <div class="inputs-bl">
10
+ <% translated_columns.each do |attribute| -%>
11
+ <%%= f.input :<%= attribute%>, :locale => locale %>
12
+ <% end -%>
13
+ </div>
14
+ </div>
15
+ <%% end -%>
16
+ <%% end -%>
17
+ <% end -%>
18
+
19
+ <div class="edit-cont">
20
+ <div class="inputs-bl">
21
+ <% model.attributes.each do |attribute, value| -%>
22
+ <% next if translated_columns.include?(attribute.to_sym) %>
23
+ <%%= f.input :<%= attribute%> %>
24
+ <% end -%>
25
+ </div>
26
+ </div>
27
+
28
+ <%%= f.button :submit %>
29
+ <%% end %>
@@ -0,0 +1,30 @@
1
+ <div class="duo-bl">
2
+ <div class="left-part">
3
+ <div class="content">
4
+ <div class="row-container">
5
+ <div class="white-row">
6
+ <div class="r-corn">
7
+ <%%= link_to t('manage.menu.<%= plural_name %>'), manage_<%= plural_name %>_path, :class=>"dark-text" %>
8
+ <div class="act-bl">
9
+ <%%= link_to t('manage.add'), new_manage_<%= singular_name %>_path, :class=>"create" %>
10
+ </div>
11
+ </div>
12
+ </div>
13
+ </div>
14
+ <div id="<%= plural_name %>" class="stage">
15
+ <%%= render :partial=>"manage/<%= plural_name %>/<%= singular_name %>", :collection=>@<%= plural_name %> %>
16
+ <%%= paginate @<%= plural_name %> %>
17
+ </div>
18
+ <script type='text/javascript'>
19
+ $(document).ready(function(){
20
+ Manage.init_collection('<%= plural_name %>', 'dinamic-bl');
21
+ });
22
+ </script>
23
+ </div>
24
+ </div>
25
+ <div class="right-part">
26
+ <div class="filter-right">
27
+ <%%= render :partial=>"manage/<%= plural_name %>/model_filter" %>
28
+ </div>
29
+ </div>
30
+ </div>
@@ -0,0 +1,27 @@
1
+ <%%= content_tag(:div, :id=>dom_id(<%= singular_name %>), :class=>"dinamic-bl") do %>
2
+ <div class="act-bl" style="display:none;">
3
+ <%%= link_to image_tag("manage/ico_edit.gif", :alt=>t('manage.edit'), :title=>t('manage.edit')), edit_manage_<%= singular_name %>_path(:id=><%= singular_name %>.id), :class=>"icons" %>
4
+
5
+ <%%= link_to image_tag("manage/ico_del.gif", :alt=>t('manage.delete'), :title=>t('manage.delete')), manage_<%= singular_name %>_path(:id=><%= singular_name %>.id),
6
+ :method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
7
+ </div>
8
+
9
+ <div class="bot-bg">
10
+ <div class="dinamic-container">
11
+ <div class="right-data">
12
+ <div class="right-data-cont">
13
+ <div class="dinamic-inner">
14
+ <div class="r-block">
15
+ <div class="r-block-cont">
16
+ <%%= link_to <%= singular_name %>.title, edit_manage_<%= singular_name %>_path(:id=><%= singular_name %>.id), :class=>"title" %>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ <div class="left-data">
23
+ <span class="data"><%%= raw I18n.l(<%= singular_name %>.created_at, :format=>"<span>%d/%m</span>%Y") %></span>
24
+ </div>
25
+ </div>
26
+ </div>
27
+ <%% end %>
@@ -0,0 +1,31 @@
1
+ <div class="bot-bg">
2
+ <div class="filt-bl">
3
+ <%%= link_to_function t('manage.model_filter.title'), "Manage.toggle_element('block_filter')", :class=>"dark-arr" %>
4
+
5
+ <%%= cookie_content_tag(:div, :id=>"block_filter", :class=>"filt") do %>
6
+ <%%= form_for @search, :as => :search, :url=>manage_<%= plural_name %>_path, :html=>{:method=>:get, :id=>"form_filter"} do |f| %>
7
+ <% model.attributes.each do |attribute, value| -%>
8
+ <%%= f.label :<%= attribute %>, t('<%= singular_name %>.<%= attribute %>', :scope => [:activerecord, :attributes]) %>
9
+ <%%= f.text_field :<%= attribute %>, :class=>"text" %>
10
+ <% end -%>
11
+
12
+ <div class="buts">
13
+ <%%= f.submit t('manage.model_filter.search'), :style=>"display:none;" %>
14
+ <%%= link_to_function content_tag(:span, t('manage.model_filter.search')), "$('#form_filter').submit()", :class=>"gr" %>
15
+ <%%= link_to t('manage.model_filter.clear'), manage_<%= plural_name %>_path, :class=>"erase" %>
16
+ </div>
17
+ <%% end %>
18
+ <%% end %>
19
+ </div>
20
+ <div class="sort">
21
+ <label><%%= t('manage.sort') %></label>
22
+ <div class="select-input"><%%= link_to_function t("<%= plural_name %>.#{@search.order_column}_#{@search.order_type}", :scope => [:manage, :sort_columns], :default => :"#{@search.order_column}_#{@search.order_type}"), "SelectList.toggle(event)", :class=>"corn", :id=>'sort_select' %></div>
23
+ <div id='sort_select_list' class="select-list" style='display:none;'>
24
+ <% model.attributes.each do |attribute, value| %>
25
+ <%%= link_to_sort(t('<%= plural_name %>.<%= attribute %>_desc', :scope => [:manage, :sort_columns], :default => :<%= attribute %>_desc), :name => <%= attribute.inspect %>, :order_type => 'desc') %>
26
+ <%%= link_to_sort(t('<%= plural_name %>.<%= attribute %>_asc', :scope => [:manage, :sort_columns], :default => :<%= attribute %>_asc), :name => <%= attribute.inspect %>, :order_type => 'asc') %>
27
+ <% end %>
28
+ </div>
29
+ </div>
30
+
31
+ </div>
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%%= t('manage.add') %>:</div>
4
+ <%%= render :partial => 'manage/<%= plural_name %>/form' %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,17 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%%= @<%= singular_name %>.name %>:</div>
4
+ <div class="edit-cont">
5
+ <table border="0" cellspacing="0" cellpadding="0" class="page-info">
6
+ <tbody>
7
+ <%% @<%= singular_name %>.attributes.each do |attribute, value| %>
8
+ <tr>
9
+ <td><strong><%%= attribute %></strong></td>
10
+ <td><%%= value %></td>
11
+ </tr>
12
+ <%% end %>
13
+ </tbody>
14
+ </table>
15
+ </div>
16
+ </div>
17
+ </div>
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module SunriseScaffold
4
+ autoload :Utils, 'sunrise_scaffold/utils'
5
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ module SunriseScaffold
3
+ class Utils
4
+ class << self
5
+ def parameterize_filename(filename)
6
+ extension = File.extname(filename)
7
+ basename = filename.gsub(/#{extension}$/, "")
8
+
9
+ [basename.parameterize('_'), extension].join.downcase
10
+ end
11
+
12
+ def form_field(form_name, field_name, column, options={})
13
+ field = case column.type
14
+ when :string, :binary, :integer, :float, :decimal then
15
+ options[:class] = "'text'"
16
+ "text_field"
17
+ when :boolean then "check_box"
18
+ when :datetime, :date, :timestamp, :time then
19
+ options[:extra_html] ||= "<script type='text/javascript'>
20
+ $(function() {
21
+ $('\##{form_name}_#{field_name}').datepicker({
22
+ numberOfMonths: 1,
23
+ dateFormat: 'dd.mm.yy'
24
+ });
25
+ });
26
+ </script>"
27
+ 'text_field'
28
+ when :text then
29
+ options[:cols] ||= 70
30
+ options[:rows] ||= 5
31
+ "text_area"
32
+ end
33
+
34
+ extra_html = options.delete(:extra_html) || ''
35
+
36
+ options_fields = []
37
+ options.each { |k, v| options_fields << ":#{k}=>#{v}" }
38
+
39
+ options_str = ", {#{options_fields.join(', ')}}" unless options_fields.empty?
40
+ options_str ||= ''
41
+
42
+ "<%= #{form_name}.#{field} #{field_name}#{options_str} %>#{extra_html}"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ module SunriseScaffold
3
+ VERSION = "0.1.0".freeze
4
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunrise-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Igor Galeta
14
+ - Pavlo Galeta
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-05-18 00:00:00 +03:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Sunrise is a Aimbulance CMS
24
+ email: galeta.igor@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - README.rdoc
33
+ - Rakefile
34
+ - lib/generators/sunrise_scaffold/USAGE
35
+ - lib/generators/sunrise_scaffold/manage_generator.rb
36
+ - lib/generators/sunrise_scaffold/templates/multiplay/controller.rb
37
+ - lib/generators/sunrise_scaffold/templates/multiplay/functional_test.rb
38
+ - lib/generators/sunrise_scaffold/templates/multiplay/helper.rb
39
+ - lib/generators/sunrise_scaffold/templates/multiplay/views/edit.html.erb
40
+ - lib/generators/sunrise_scaffold/templates/multiplay/views/form.html.erb
41
+ - lib/generators/sunrise_scaffold/templates/multiplay/views/index.html.erb
42
+ - lib/generators/sunrise_scaffold/templates/multiplay/views/item.html.erb
43
+ - lib/generators/sunrise_scaffold/templates/multiplay/views/model_filter.html.erb
44
+ - lib/generators/sunrise_scaffold/templates/multiplay/views/new.html.erb
45
+ - lib/generators/sunrise_scaffold/templates/multiplay/views/show.html.erb
46
+ - lib/generators/sunrise_scaffold/templates/single/controller.rb
47
+ - lib/generators/sunrise_scaffold/templates/single/functional_test.rb
48
+ - lib/generators/sunrise_scaffold/templates/single/helper.rb
49
+ - lib/generators/sunrise_scaffold/templates/single/views/edit.html.erb
50
+ - lib/generators/sunrise_scaffold/templates/single/views/form.html.erb
51
+ - lib/generators/sunrise_scaffold/templates/single/views/index.html.erb
52
+ - lib/generators/sunrise_scaffold/templates/single/views/item.html.erb
53
+ - lib/generators/sunrise_scaffold/templates/single/views/model_filter.html.erb
54
+ - lib/generators/sunrise_scaffold/templates/single/views/new.html.erb
55
+ - lib/generators/sunrise_scaffold/templates/single/views/show.html.erb
56
+ - lib/sunrise_scaffold.rb
57
+ - lib/sunrise_scaffold/utils.rb
58
+ - lib/sunrise_scaffold/version.rb
59
+ has_rdoc: true
60
+ homepage: https://github.com/galetahub/sunrise-scaffold
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.6.2
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Rails CMS
93
+ test_files: []
94
+