pixelearth 0.0.1 → 0.0.2
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/Gemfile +0 -6
- data/lib/generators/project_files/USAGE +7 -0
- data/lib/generators/project_files/project_files_generator.rb +40 -0
- data/lib/generators/project_files/templates/images/icons/accept.png +0 -0
- data/lib/generators/project_files/templates/images/icons/back.png +0 -0
- data/lib/generators/project_files/templates/images/icons/block.png +0 -0
- data/lib/generators/project_files/templates/images/icons/destroy.png +0 -0
- data/lib/generators/project_files/templates/images/icons/dialog.png +0 -0
- data/lib/generators/project_files/templates/images/icons/edit.png +0 -0
- data/lib/generators/project_files/templates/images/icons/help.png +0 -0
- data/lib/generators/project_files/templates/images/icons/info.png +0 -0
- data/lib/generators/project_files/templates/images/icons/list_all.png +0 -0
- data/lib/generators/project_files/templates/images/icons/new.png +0 -0
- data/lib/generators/project_files/templates/images/icons/next.png +0 -0
- data/lib/generators/project_files/templates/images/icons/process.png +0 -0
- data/lib/generators/project_files/templates/images/icons/show.png +0 -0
- data/lib/generators/project_files/templates/images/icons/user.png +0 -0
- data/lib/generators/project_files/templates/images/icons/users.png +0 -0
- data/lib/generators/project_files/templates/images/icons/warning.png +0 -0
- data/lib/generators/project_files/templates/stylesheets/sass/pixelearth.scss +162 -0
- data/lib/generators/project_files/templates/stylesheets/sass/validation_errors.scss +36 -0
- data/lib/generators/project_files/templates/tmp/_form.html.haml +16 -0
- data/lib/generators/project_files/templates/view_templates/haml/controller/view.html.haml +0 -0
- data/lib/generators/project_files/templates/view_templates/haml/mailer/view.text.haml +3 -0
- data/lib/generators/project_files/templates/view_templates/haml/scaffold/_form.html.haml +7 -0
- data/lib/generators/project_files/templates/view_templates/haml/scaffold/edit.html.haml +3 -0
- data/lib/generators/project_files/templates/view_templates/haml/scaffold/index.html.haml +17 -0
- data/lib/generators/project_files/templates/view_templates/haml/scaffold/new.html.haml +3 -0
- data/lib/generators/project_files/templates/view_templates/haml/scaffold/show.html.haml +8 -0
- data/lib/generators/project_files/templates/view_templates/rails/scaffold_controller/controller.rb +39 -0
- data/lib/generators/project_files/templates/views/application.html.haml +51 -0
- data/lib/generators/project_files/templates/views/shared/_admin_buttons.html.haml +20 -0
- data/lib/generators/project_files/templates/views/shared/_form_errors.html.haml +8 -0
- data/lib/generators/project_files/templates/views/shared/_show_edit_destroy.html.haml +6 -0
- data/lib/pixelearth/version.rb +1 -1
- data/lib/pixelearth.rb +13 -6
- data/lib/required/active_record.rb +8 -0
- data/lib/required/application_controller.rb +210 -0
- data/lib/required/application_helper.rb +73 -0
- data/lib/required/date_formats.rb +5 -0
- data/lib/required/rails_core_mods.rb +2 -0
- data/lib/required/ruby_core_mods.rb +17 -0
- data/lib/required/sass.rb +1 -0
- data/lib/required/string.rb +6 -0
- data/pixelearth.gemspec +13 -0
- metadata +130 -6
data/Gemfile
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
class ProjectFilesGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__) #this is for thor
|
3
|
+
|
4
|
+
def copy_template_files
|
5
|
+
gem_template_dir = File.expand_path('../templates', __FILE__) #this is for me : )
|
6
|
+
app_root = destination_root
|
7
|
+
|
8
|
+
#copy view templates
|
9
|
+
cmd = "mkdir -v #{app_root}/lib/templates"
|
10
|
+
puts `#{cmd}`
|
11
|
+
cmd = "cp -vR #{gem_template_dir}/view_templates/* #{app_root}/lib/templates/"
|
12
|
+
puts `#{cmd}`
|
13
|
+
|
14
|
+
#make shared dir
|
15
|
+
cmd = "mkdir -v #{app_root}/app/views/shared/"
|
16
|
+
puts `#{cmd}`
|
17
|
+
|
18
|
+
#copy shared
|
19
|
+
cmd = "cp -vR #{gem_template_dir}/views/shared/* #{app_root}/app/views/shared/"
|
20
|
+
puts `#{cmd}`
|
21
|
+
|
22
|
+
#copy layout
|
23
|
+
cmd = "cp -vR #{gem_template_dir}/views/application.html.haml #{app_root}/app/views/layouts/"
|
24
|
+
puts `#{cmd}`
|
25
|
+
|
26
|
+
#remove erb layout file here
|
27
|
+
|
28
|
+
#copy images
|
29
|
+
cmd = "cp -vR #{gem_template_dir}/images/* #{app_root}/public/images/"
|
30
|
+
puts `#{cmd}`
|
31
|
+
|
32
|
+
#copy stylesheets
|
33
|
+
cmd = "cp -vR #{gem_template_dir}/stylesheets/* #{app_root}/public/stylesheets/"
|
34
|
+
puts `#{cmd}`
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,162 @@
|
|
1
|
+
//@import "vars.scss";
|
2
|
+
|
3
|
+
body {
|
4
|
+
margin:0;
|
5
|
+
padding:0;
|
6
|
+
background-color:#333333;
|
7
|
+
color:#444444;
|
8
|
+
font-size:85%;
|
9
|
+
font-family:arial;
|
10
|
+
}
|
11
|
+
h1, h2, h3 {
|
12
|
+
margin-top:12px;
|
13
|
+
color: #2B4F81;
|
14
|
+
margin-bottom:8px;
|
15
|
+
}
|
16
|
+
h1 {
|
17
|
+
}
|
18
|
+
#container_1 {
|
19
|
+
width:1000px;
|
20
|
+
border-right:1px solid #555;
|
21
|
+
}
|
22
|
+
div.content {
|
23
|
+
padding: 15px;
|
24
|
+
background-color:white;
|
25
|
+
}
|
26
|
+
|
27
|
+
a {
|
28
|
+
color:#EB9A00;
|
29
|
+
text-decoration:none;
|
30
|
+
&:hover {
|
31
|
+
color:orange;
|
32
|
+
}
|
33
|
+
img {
|
34
|
+
border:0;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
table {
|
39
|
+
}
|
40
|
+
|
41
|
+
table td, table th {
|
42
|
+
padding:5px 10px;
|
43
|
+
vertical-align:top;
|
44
|
+
}
|
45
|
+
table th {
|
46
|
+
background-color:#F9F9F9;
|
47
|
+
border-bottom:1px solid #cccccc;
|
48
|
+
text-align:left;
|
49
|
+
|
50
|
+
}
|
51
|
+
table td {
|
52
|
+
background-color:#fafafa;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
table.data {
|
57
|
+
width:100%;
|
58
|
+
tr.b td {
|
59
|
+
background-color:#FBFBE3;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
/* admin controls */
|
63
|
+
a.index_show,
|
64
|
+
a.index_edit,
|
65
|
+
a.index_destroy
|
66
|
+
{
|
67
|
+
display:inline-block;
|
68
|
+
width:28px; height:28px;
|
69
|
+
text-indent: -9999px;
|
70
|
+
background-position: center center;
|
71
|
+
background-repeat: no-repeat;
|
72
|
+
}
|
73
|
+
a.index_show {
|
74
|
+
background: url(/images/icons/show.png) center center no-repeat;
|
75
|
+
}
|
76
|
+
a.index_edit {
|
77
|
+
background: url(/images/icons/edit.png) center center no-repeat;
|
78
|
+
}
|
79
|
+
a.index_destroy {
|
80
|
+
background: url(/images/icons/destroy.png) center center no-repeat;
|
81
|
+
}
|
82
|
+
|
83
|
+
/* buttons */
|
84
|
+
#admin_buttons {
|
85
|
+
margin: 30px 0 0 0;
|
86
|
+
}
|
87
|
+
.show_edit_destroy_box {
|
88
|
+
width: 95px;
|
89
|
+
img {
|
90
|
+
width:24px;
|
91
|
+
height:24px;
|
92
|
+
vertical-align: bottom;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
/* show page */
|
97
|
+
.resource_label {
|
98
|
+
background-color:#eee;
|
99
|
+
width:200px;
|
100
|
+
height:15px;
|
101
|
+
padding:5px;
|
102
|
+
}
|
103
|
+
.resource_value {
|
104
|
+
margin-left:220px;
|
105
|
+
margin-top:-25px;
|
106
|
+
padding:5px;
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
label {
|
111
|
+
font-weight:800;
|
112
|
+
color:#2B4F81;
|
113
|
+
}
|
114
|
+
div.field {
|
115
|
+
padding:5px 0px;
|
116
|
+
}
|
117
|
+
.debug_dump {
|
118
|
+
|
119
|
+
|
120
|
+
}
|
121
|
+
/* columns */
|
122
|
+
|
123
|
+
.col_of_3 {
|
124
|
+
float:left;
|
125
|
+
width:30%;
|
126
|
+
}
|
127
|
+
.wrapper {
|
128
|
+
padding:10px;
|
129
|
+
}
|
130
|
+
|
131
|
+
#footer {
|
132
|
+
background-color:#333333;
|
133
|
+
color:white;
|
134
|
+
padding:15px 30px;
|
135
|
+
}
|
136
|
+
/* flash */
|
137
|
+
.flash {
|
138
|
+
padding: 15px 15px 15px 66px;
|
139
|
+
border:1px solid #D5D700;
|
140
|
+
border-left:0;
|
141
|
+
border-right:0;
|
142
|
+
background: #FFFCDB url(/images/icons/dialog.png) 5px center no-repeat;
|
143
|
+
color: #D7B206;
|
144
|
+
}
|
145
|
+
.flash_success {
|
146
|
+
border-color: #0B7305;
|
147
|
+
background-color:#DBFFE0;
|
148
|
+
color:#0B7305;
|
149
|
+
}
|
150
|
+
/* rounded */
|
151
|
+
.rounded_10 {
|
152
|
+
-moz-border-radius: 10px;
|
153
|
+
-webkit-border-radius: 10px;
|
154
|
+
border-radius: 10px;
|
155
|
+
}
|
156
|
+
.rounded_5 {
|
157
|
+
-moz-border-radius: 5px;
|
158
|
+
-webkit-border-radius: 5px;
|
159
|
+
border-radius: 5px;
|
160
|
+
}
|
161
|
+
|
162
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
.field_with_errors {
|
3
|
+
padding: 2px;
|
4
|
+
background-color: #FFEBEB;
|
5
|
+
display:inline;
|
6
|
+
label {
|
7
|
+
color: #CC0000;
|
8
|
+
font-weight:800;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
#error_explanation {
|
13
|
+
width: 450px;
|
14
|
+
border: 0px solid red;
|
15
|
+
padding: 7px;
|
16
|
+
padding-bottom: 2px;
|
17
|
+
margin-bottom: 20px;
|
18
|
+
background-color: #FFEBEB;
|
19
|
+
}
|
20
|
+
|
21
|
+
#error_explanation h2 {
|
22
|
+
text-align: left;
|
23
|
+
font-weight: bold;
|
24
|
+
padding: 5px 5px 5px 15px;
|
25
|
+
font-size: 12px;
|
26
|
+
margin: -7px;
|
27
|
+
margin-bottom: 0px;
|
28
|
+
background-color: #c00;
|
29
|
+
color: #FFEBEB;
|
30
|
+
}
|
31
|
+
|
32
|
+
#error_explanation ul li {
|
33
|
+
font-size: 12px;
|
34
|
+
list-style: square;
|
35
|
+
}
|
36
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
//replaced by formtastic form
|
2
|
+
= form_for @resource do |f|
|
3
|
+
|
4
|
+
=form_errors_helper
|
5
|
+
|
6
|
+
<% for attribute in attributes -%>
|
7
|
+
.field
|
8
|
+
.field_label
|
9
|
+
= f.label :<%= attribute.name %>
|
10
|
+
.field_input
|
11
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>
|
12
|
+
<% end -%>
|
13
|
+
.actions
|
14
|
+
= f.submit 'Save'
|
15
|
+
|
16
|
+
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
%table.data.admin
|
2
|
+
%tr
|
3
|
+
<% for attribute in attributes -%>
|
4
|
+
%th <%= attribute.human_name %>
|
5
|
+
<% end -%>
|
6
|
+
%th
|
7
|
+
|
8
|
+
- @resources.each do |x|
|
9
|
+
%tr{:class => cycle('a','b')}
|
10
|
+
<% for attribute in attributes -%>
|
11
|
+
%td= x.<%= attribute.name %>
|
12
|
+
<% end -%>
|
13
|
+
%td= show_edit_destroy x
|
14
|
+
|
15
|
+
|
16
|
+
= admin_buttons
|
17
|
+
|
data/lib/generators/project_files/templates/view_templates/rails/scaffold_controller/controller.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
|
3
|
+
before_filter :get_resource, :except => []
|
4
|
+
|
5
|
+
def index
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
end
|
13
|
+
|
14
|
+
def edit
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
if @resource.save
|
19
|
+
redirect_to(@resource, :notice => '<%= human_name %> was successfully created.')
|
20
|
+
else
|
21
|
+
render :action => "new"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
if @resource.update_attributes(params[:<%= singular_table_name %>])
|
27
|
+
redirect_to(@resource, :notice => '<%= human_name %> was successfully updated.')
|
28
|
+
else
|
29
|
+
render :action => "edit"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
@resource.destroy
|
35
|
+
|
36
|
+
redirect_to(<%= index_helper %>_url, :notice => '<%= human_name %> was successfully removed.')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
/%link{ :rel => "shortcut icon", :href => "/favicon.ico", :type => "image/x-icon"}/
|
5
|
+
%title
|
6
|
+
= @layout[:title] || default_view_title
|
7
|
+
%meta{:name => 'keywords' , :content => @layout[:keywords]}
|
8
|
+
%meta{:name => 'description' , :content => @layout[:desc]}
|
9
|
+
%meta{:name => 'robots' , :content => @layout[:all]}
|
10
|
+
%meta{'http-equiv' => 'content-type' , :content => "text/html; charset=utf-8"}
|
11
|
+
|
12
|
+
= csrf_meta_tag
|
13
|
+
= stylesheet_link_tag @layout[:css].flatten.uniq
|
14
|
+
= javascript_include_tag :defaults
|
15
|
+
|
16
|
+
/must be called before noConflict
|
17
|
+
= javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'
|
18
|
+
|
19
|
+
:javascript
|
20
|
+
jQuery.noConflict(); //must be run before any other 'plugins' that use these libraries
|
21
|
+
|
22
|
+
= javascript_include_tag @layout[:js].flatten.uniq
|
23
|
+
|
24
|
+
%style
|
25
|
+
= yield :styles
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
%body
|
31
|
+
|
32
|
+
|
33
|
+
#container_1
|
34
|
+
.content
|
35
|
+
|
36
|
+
/Flash Message
|
37
|
+
= raw display_flash
|
38
|
+
|
39
|
+
|
40
|
+
- if @layout[:show_h1]
|
41
|
+
%h1
|
42
|
+
= raw @layout[:h1] || default_view_title
|
43
|
+
|
44
|
+
|
45
|
+
=yield
|
46
|
+
|
47
|
+
=clear
|
48
|
+
|
49
|
+
#footer
|
50
|
+
#debug_box
|
51
|
+
=debug params
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#admin_buttons
|
2
|
+
|
3
|
+
-case params[:action]
|
4
|
+
-when 'index'
|
5
|
+
//new
|
6
|
+
=link_to image_tag('/images/icons/new.png', :alt=>'[new]'), send("new_#{params[:controller].singularize}_path"), :class => 'admin_new', :title => 'New'
|
7
|
+
-when 'new', 'create'
|
8
|
+
//index
|
9
|
+
=link_to image_tag('/images/icons/list_all.png', :alt=>"[List All #{params[:controller].titleize}]"), send("#{params[:controller]}_path"), :class => 'admin_list', :title => "All #{params[:controller].titleize}"
|
10
|
+
-when 'show'
|
11
|
+
//edit, index
|
12
|
+
=link_to image_tag('/images/icons/list_all.png', :alt=>"[List All #{params[:controller].titleize}]"), send("#{params[:controller]}_path"), :class => 'admin_list', :title => "List All #{params[:controller].titleize}"
|
13
|
+
=link_to image_tag('/images/icons/edit.png', :alt=>"[Edit]"), send("edit_#{params[:controller].singularize}_path"), :class => 'admin_edit', :title => 'Edit'
|
14
|
+
-when 'edit', 'update'
|
15
|
+
/show, index
|
16
|
+
=link_to image_tag('/images/icons/list_all.png', :alt=>"[List All #{params[:controller].titleize}]"), send("#{params[:controller]}_path"), :class => 'admin_list', :title => "List All #{params[:controller].titleize}"
|
17
|
+
=link_to image_tag('/images/icons/show.png', :alt=>'[show]'), send("#{params[:controller].singularize}_path", @resource), :class => 'admin_show', :title => 'Show'
|
18
|
+
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
.show_edit_destroy_box
|
2
|
+
=link_to image_tag('/images/icons/show.png', :alt=>'[show]'), resource, :class => 'admin_show', :title => 'Show'
|
3
|
+
=link_to image_tag('/images/icons/edit.png', :alt=>'[edit]'), send("edit_#{resource.class.table_name.singularize}_path", resource), :class => 'admin_edit', :title => 'Edit'
|
4
|
+
=link_to image_tag('/images/icons/destroy.png', :alt=>'[destroy]'), resource, :confirm => 'Are you sure?', :method => :delete, :class => 'admin_destroy', :title => 'Destroy'
|
5
|
+
|
6
|
+
|
data/lib/pixelearth/version.rb
CHANGED
data/lib/pixelearth.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
this_dir = File.expand_path('../', __FILE__)
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
require 'haml-rails'
|
5
|
+
require 'redcloth'
|
6
|
+
require 'formtastic'
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
Dir.glob("#{this_dir}/required/*.rb").each do |x|
|
11
|
+
require x;
|
12
|
+
#puts x #this will show up in console etc.
|
7
13
|
end
|
14
|
+
|
@@ -0,0 +1,210 @@
|
|
1
|
+
#class ApplicationController < ActionController::Base #this won't work and cuases the standared ApplicationController to not load
|
2
|
+
module ActionController
|
3
|
+
class Base
|
4
|
+
|
5
|
+
before_filter :init_pixelearth_application_controller
|
6
|
+
|
7
|
+
helper_method :h1,
|
8
|
+
:strip_tags,
|
9
|
+
:tweet,
|
10
|
+
:title,
|
11
|
+
:title_h1,
|
12
|
+
:default_view_title
|
13
|
+
|
14
|
+
|
15
|
+
def init_pixelearth_application_controller #base config for layout, actions can add to this
|
16
|
+
@layout = {
|
17
|
+
:show_h1 => true,
|
18
|
+
:title => nil,
|
19
|
+
:h1 => nil,
|
20
|
+
:css => [
|
21
|
+
'sass/compiled/pixelearth',
|
22
|
+
'sass/compiled/validation_errors',
|
23
|
+
'formtastic'
|
24
|
+
],
|
25
|
+
:js => []
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# ----------- CONTROLLER --------------
|
30
|
+
#gets @resource or @resource for all actions in controller
|
31
|
+
#before filter is set per controller, thus overrideable.
|
32
|
+
def get_resource
|
33
|
+
action = params[:action].to_sym
|
34
|
+
controller = params[:controller]
|
35
|
+
klass = controller.classify.constantize
|
36
|
+
|
37
|
+
if [:show, :edit, :update, :destroy].include? action
|
38
|
+
@resource = klass.find(params[:id])
|
39
|
+
elsif action == :new
|
40
|
+
@resource = klass.new
|
41
|
+
elsif action == :create
|
42
|
+
@resource = klass.new(params[controller.singularize])
|
43
|
+
elsif action == :index
|
44
|
+
@resources = klass.all
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
# ----------- LAYOUT --------------
|
50
|
+
def title (st) #allow templates to set page title
|
51
|
+
@layout[:title] = strip_tags st
|
52
|
+
end
|
53
|
+
def h1 (st) #allow templates to set page h1
|
54
|
+
@layout[:h1] = st
|
55
|
+
end
|
56
|
+
def title_h1 (st) #allow templates to set page title and h1 at same time
|
57
|
+
h1(st)
|
58
|
+
title(st)
|
59
|
+
end
|
60
|
+
def h1_emph(st) #uniform way to make part of the h1 stand out
|
61
|
+
"<em>#{st}</em>"
|
62
|
+
end
|
63
|
+
def h1_name(st) #uniform way of displaying model names in h1
|
64
|
+
h1_emph "\"#{st.titleize}\""
|
65
|
+
end
|
66
|
+
|
67
|
+
# ----------- UTILS --------------
|
68
|
+
def strip_tags (str)
|
69
|
+
str.gsub(/<\/?[^>]*>/, "")
|
70
|
+
end
|
71
|
+
def tweet(st='')
|
72
|
+
puts "-----------#{st}----------------".green
|
73
|
+
end
|
74
|
+
def app_controllers
|
75
|
+
Dir['app/controllers/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize}
|
76
|
+
end
|
77
|
+
def app_models
|
78
|
+
Dir['app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
def default_view_title #sets h1 and <title> defaults to something sensible, in the absense of explicit setting
|
85
|
+
case params[:action]
|
86
|
+
when 'new'
|
87
|
+
title_h1 "New #{params[:controller].singularize.titleize}"
|
88
|
+
when 'create'
|
89
|
+
title_h1 "New #{params[:controller].singularize.titleize} (with errors)"
|
90
|
+
when 'show'
|
91
|
+
title_h1 "#{params[:controller].singularize.titleize}: #{@resource.name.titleize || @resource.id }"
|
92
|
+
when 'edit'
|
93
|
+
title_h1 "Editing #{params[:controller].singularize.titleize}: #{@resource.name.titleize || @resource.id }"
|
94
|
+
when 'update'
|
95
|
+
title_h1 "Editing #{params[:controller].singularize.titleize} (with errors)"
|
96
|
+
when 'index'
|
97
|
+
title_h1 "Listing #{params[:controller].titleize}"
|
98
|
+
else
|
99
|
+
"{Default Title}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
class ApplicationController < ActionController::Base
|
106
|
+
|
107
|
+
helper_method :h1,
|
108
|
+
:strip_tags,
|
109
|
+
:tweet,
|
110
|
+
:title,
|
111
|
+
:title_h1,
|
112
|
+
:default_view_title
|
113
|
+
|
114
|
+
|
115
|
+
@layout = {}
|
116
|
+
|
117
|
+
|
118
|
+
# ----------- CONTROLLER --------------
|
119
|
+
#gets @resource or @resource for all actions in controller
|
120
|
+
#before filter is set per controller, thus overrideable.
|
121
|
+
def get_resource
|
122
|
+
puts '-----'+params[:controller]
|
123
|
+
action = params[:action].to_sym
|
124
|
+
controller = params[:controller]
|
125
|
+
klass = controller.classify.constantize
|
126
|
+
|
127
|
+
if [:show, :edit, :update, :destroy].include? action
|
128
|
+
@resource = klass.find(params[:id])
|
129
|
+
elsif action == :new
|
130
|
+
@resource = klass.new
|
131
|
+
elsif action == :create
|
132
|
+
@resource = klass.new(params[controller.singularize])
|
133
|
+
elsif action == :index
|
134
|
+
@resources = klass.all
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
# ----------- LAYOUT --------------
|
140
|
+
def title (st) #allow templates to set page title
|
141
|
+
@layout[:title] = strip_tags st
|
142
|
+
end
|
143
|
+
def h1 (st) #allow templates to set page h1
|
144
|
+
@layout[:h1] = st
|
145
|
+
end
|
146
|
+
def title_h1 (st) #allow templates to set page title and h1 at same time
|
147
|
+
h1(st)
|
148
|
+
title(st)
|
149
|
+
end
|
150
|
+
def h1_emph(st) #uniform way to make part of the h1 stand out
|
151
|
+
"<em>#{st}</em>"
|
152
|
+
end
|
153
|
+
def h1_name(st) #uniform way of displaying model names in h1
|
154
|
+
h1_emph "\"#{st.titleize}\""
|
155
|
+
end
|
156
|
+
|
157
|
+
# ----------- UTILS --------------
|
158
|
+
def strip_tags (str)
|
159
|
+
str.gsub(/<\/?[^>]*>/, "")
|
160
|
+
end
|
161
|
+
def tweet(st='')
|
162
|
+
puts "-----------#{st}----------------".green
|
163
|
+
end
|
164
|
+
def app_controllers
|
165
|
+
Dir['app/controllers/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize}
|
166
|
+
end
|
167
|
+
def app_models
|
168
|
+
Dir['app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
private
|
174
|
+
def default_view_title #sets h1 and <title> defaults to something sensible, in the absense of explicit setting
|
175
|
+
resource = get_resource_from_params
|
176
|
+
|
177
|
+
return if resource.nil?
|
178
|
+
|
179
|
+
case params[:action]
|
180
|
+
when 'new'
|
181
|
+
title_h1 "New #{params[:controller].singularize.titleize}"
|
182
|
+
when 'create'
|
183
|
+
title_h1 "New #{params[:controller].singularize.titleize} (with errors)"
|
184
|
+
when 'show'
|
185
|
+
title_h1 "#{params[:controller].singularize.titleize}: #{resource.name.titleize || resource.id }"
|
186
|
+
when 'edit'
|
187
|
+
title_h1 "Editing #{params[:controller].singularize.titleize}: #{resource.name.titleize || resource.id }"
|
188
|
+
when 'update'
|
189
|
+
title_h1 "Editing #{params[:controller].singularize.titleize} (with errors)"
|
190
|
+
when 'index'
|
191
|
+
title_h1 "Listing #{params[:controller].titleize}"
|
192
|
+
else
|
193
|
+
"{Default Title}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
def get_resource_from_params #gets @event for url events/show, and @events from /events/index
|
197
|
+
begin #nested controllers are working at the moment.
|
198
|
+
if params[:action] == 'index'
|
199
|
+
instance_variable_get('@' + params[:controller])
|
200
|
+
else
|
201
|
+
instance_variable_get('@' + params[:controller].singularize)
|
202
|
+
end
|
203
|
+
rescue
|
204
|
+
nil
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ApplicationHelper
|
2
|
+
|
3
|
+
|
4
|
+
#------------------------------LAYOUT-------------------------------------
|
5
|
+
def display_flash (type = nil)
|
6
|
+
|
7
|
+
if type.nil? #show all flash keys
|
8
|
+
html = flash.collect { |type, val| display_flash(type) }
|
9
|
+
else
|
10
|
+
return flash[type].blank? ? "" : "<p class='flash flash_#{type}'>#{flash[type]}</p> \n"
|
11
|
+
end
|
12
|
+
|
13
|
+
html
|
14
|
+
end
|
15
|
+
def on_if_current (path)
|
16
|
+
if path == request.fullpath
|
17
|
+
'on'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def on_if_controller (c)
|
21
|
+
if params[:controller] == c.to_s
|
22
|
+
'on'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
def tr (d)
|
26
|
+
# Quick array to table row.
|
27
|
+
# Takes an array and creates a table row (tr) with each element of the array
|
28
|
+
# occupying one column (td).
|
29
|
+
o = "<tr>\n"
|
30
|
+
d.each do |x|
|
31
|
+
o << "\t<td>#{x}</td>\n"
|
32
|
+
end
|
33
|
+
o << "</tr>\n"
|
34
|
+
o
|
35
|
+
end
|
36
|
+
def titled_link_to (resource)
|
37
|
+
link_to(resource.name.titleize, send("#{resource.class.to_s.underscore}_path", resource), :title => "View Full #{resource.class.to_s.titleize} Details for #{h resource.name.titleize}")
|
38
|
+
end
|
39
|
+
def short_text(st, len=100)
|
40
|
+
raw truncate( strip_tags( raw(st)), :length=>len)
|
41
|
+
end
|
42
|
+
def row_toggle
|
43
|
+
cycle('a','b')
|
44
|
+
end
|
45
|
+
def date(date, format=:default)
|
46
|
+
#ref: http://snippets.dzone.com/posts/show/2255
|
47
|
+
formats = {
|
48
|
+
:default => "%b %d, %Y",
|
49
|
+
:numbers => "%m-%d-%y",
|
50
|
+
:date_time => "%b %d, %Y %I:%M %p",
|
51
|
+
:just_time => "%I:%M %p",
|
52
|
+
}
|
53
|
+
date.strftime(formats[format])
|
54
|
+
|
55
|
+
end
|
56
|
+
def clear
|
57
|
+
raw "<br style='clear:both'/>"
|
58
|
+
end
|
59
|
+
|
60
|
+
#------------------------------ADMIN-------------------------------------
|
61
|
+
def form_errors_helper
|
62
|
+
render :partial => 'shared/form_errors'
|
63
|
+
end
|
64
|
+
def admin_buttons
|
65
|
+
render :partial => 'shared/admin_buttons'
|
66
|
+
end
|
67
|
+
def show_edit_destroy(resource)
|
68
|
+
render :partial => 'shared/show_edit_destroy', :locals => {:resource => resource}
|
69
|
+
end
|
70
|
+
def link_to_destroy
|
71
|
+
raw link_to('destroy', @resource, :confirm => 'Are you sure you want to remove this?', :method => :delete, :title => 'remove permanently')
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class String
|
2
|
+
def first_caps
|
3
|
+
self.split(/ /).map{|x| x.capitalize}.join(' ')
|
4
|
+
end
|
5
|
+
def sp_to_underscore #fills in the gap in rails inflectors, since their #underscore method only works for CamelCase
|
6
|
+
self.downcase.gsub(/\s+/,"_")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Dir
|
11
|
+
def filter(regex)
|
12
|
+
self.select do |x|
|
13
|
+
x =~ regex
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
Sass::Plugin.options[:css_location] = 'public/stylesheets/sass/compiled'
|
data/pixelearth.gemspec
CHANGED
@@ -12,6 +12,19 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{Pixel Earth work flow gem}
|
13
13
|
s.description = %q{Makes life sweeter}
|
14
14
|
|
15
|
+
#these need to be included manually in pixelearth.rb
|
16
|
+
s.add_dependency "haml-rails"
|
17
|
+
s.add_dependency "RedCloth"
|
18
|
+
s.add_dependency "formtastic"
|
19
|
+
|
20
|
+
|
21
|
+
s.add_development_dependency "ruby-debug"
|
22
|
+
s.add_development_dependency "redgreen" #colorizes output for tests, 'required' test/test_helper.rb
|
23
|
+
s.add_development_dependency "colored" #colored output in terminal http://github.com/defunkt/colored/blob/master/lib/colored.rb
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
15
28
|
s.rubyforge_project = ""
|
16
29
|
|
17
30
|
s.files = `git ls-files`.split("\n")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixelearth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Lieb
|
@@ -15,10 +15,93 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-09 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: haml-rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: RedCloth
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: formtastic
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: ruby-debug
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: redgreen
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: colored
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
version_requirements: *id006
|
22
105
|
description: Makes life sweeter
|
23
106
|
email:
|
24
107
|
- red@pixelearth.net
|
@@ -32,8 +115,49 @@ files:
|
|
32
115
|
- .gitignore
|
33
116
|
- Gemfile
|
34
117
|
- Rakefile
|
118
|
+
- lib/generators/project_files/USAGE
|
119
|
+
- lib/generators/project_files/project_files_generator.rb
|
120
|
+
- lib/generators/project_files/templates/images/icons/accept.png
|
121
|
+
- lib/generators/project_files/templates/images/icons/back.png
|
122
|
+
- lib/generators/project_files/templates/images/icons/block.png
|
123
|
+
- lib/generators/project_files/templates/images/icons/destroy.png
|
124
|
+
- lib/generators/project_files/templates/images/icons/dialog.png
|
125
|
+
- lib/generators/project_files/templates/images/icons/edit.png
|
126
|
+
- lib/generators/project_files/templates/images/icons/help.png
|
127
|
+
- lib/generators/project_files/templates/images/icons/info.png
|
128
|
+
- lib/generators/project_files/templates/images/icons/list_all.png
|
129
|
+
- lib/generators/project_files/templates/images/icons/new.png
|
130
|
+
- lib/generators/project_files/templates/images/icons/next.png
|
131
|
+
- lib/generators/project_files/templates/images/icons/process.png
|
132
|
+
- lib/generators/project_files/templates/images/icons/show.png
|
133
|
+
- lib/generators/project_files/templates/images/icons/user.png
|
134
|
+
- lib/generators/project_files/templates/images/icons/users.png
|
135
|
+
- lib/generators/project_files/templates/images/icons/warning.png
|
136
|
+
- lib/generators/project_files/templates/stylesheets/sass/pixelearth.scss
|
137
|
+
- lib/generators/project_files/templates/stylesheets/sass/validation_errors.scss
|
138
|
+
- lib/generators/project_files/templates/tmp/_form.html.haml
|
139
|
+
- lib/generators/project_files/templates/view_templates/haml/controller/view.html.haml
|
140
|
+
- lib/generators/project_files/templates/view_templates/haml/mailer/view.text.haml
|
141
|
+
- lib/generators/project_files/templates/view_templates/haml/scaffold/_form.html.haml
|
142
|
+
- lib/generators/project_files/templates/view_templates/haml/scaffold/edit.html.haml
|
143
|
+
- lib/generators/project_files/templates/view_templates/haml/scaffold/index.html.haml
|
144
|
+
- lib/generators/project_files/templates/view_templates/haml/scaffold/new.html.haml
|
145
|
+
- lib/generators/project_files/templates/view_templates/haml/scaffold/show.html.haml
|
146
|
+
- lib/generators/project_files/templates/view_templates/rails/scaffold_controller/controller.rb
|
147
|
+
- lib/generators/project_files/templates/views/application.html.haml
|
148
|
+
- lib/generators/project_files/templates/views/shared/_admin_buttons.html.haml
|
149
|
+
- lib/generators/project_files/templates/views/shared/_form_errors.html.haml
|
150
|
+
- lib/generators/project_files/templates/views/shared/_show_edit_destroy.html.haml
|
35
151
|
- lib/pixelearth.rb
|
36
152
|
- lib/pixelearth/version.rb
|
153
|
+
- lib/required/active_record.rb
|
154
|
+
- lib/required/application_controller.rb
|
155
|
+
- lib/required/application_helper.rb
|
156
|
+
- lib/required/date_formats.rb
|
157
|
+
- lib/required/rails_core_mods.rb
|
158
|
+
- lib/required/ruby_core_mods.rb
|
159
|
+
- lib/required/sass.rb
|
160
|
+
- lib/required/string.rb
|
37
161
|
- pixelearth.gemspec
|
38
162
|
has_rdoc: true
|
39
163
|
homepage: ""
|