wontomedia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +661 -0
- data/COPYING.DOCUMENTATION +450 -0
- data/LICENSE +661 -0
- data/README.markdown +56 -0
- data/Rakefile +185 -0
- data/VERSION.yml +4 -0
- data/app/controllers/admin_controller.rb +144 -0
- data/app/controllers/application_controller.rb +29 -0
- data/app/controllers/connections_controller.rb +150 -0
- data/app/controllers/items_controller.rb +365 -0
- data/app/helpers/connections_helper.rb +67 -0
- data/app/helpers/format_helper.rb +154 -0
- data/app/helpers/items_helper.rb +105 -0
- data/app/models/category_item.rb +23 -0
- data/app/models/connection.rb +210 -0
- data/app/models/individual_item.rb +23 -0
- data/app/models/item.rb +86 -0
- data/app/models/property_item.rb +23 -0
- data/app/models/qualified_item.rb +23 -0
- data/app/views/admin/index.html.erb +74 -0
- data/app/views/connections/_index_outbound_links.html.erb +48 -0
- data/app/views/connections/_spo_select_controls.html.erb +151 -0
- data/app/views/connections/edit.html.erb +70 -0
- data/app/views/connections/index.html.erb +84 -0
- data/app/views/connections/new.html.erb +61 -0
- data/app/views/connections/show.html.erb +110 -0
- data/app/views/items/_active_content.html.erb +26 -0
- data/app/views/items/_content_examples.html.erb +55 -0
- data/app/views/items/_core_tasks.html.erb +23 -0
- data/app/views/items/_form_fields.html.erb +69 -0
- data/app/views/items/_list_outbound_links.html.erb +58 -0
- data/app/views/items/_screen_select.html.erb +24 -0
- data/app/views/items/_show_outbound_links.html.erb +70 -0
- data/app/views/items/_topic_list.html.erb +26 -0
- data/app/views/items/_type_select.html.erb +47 -0
- data/app/views/items/edit.html.erb +63 -0
- data/app/views/items/index.html.erb +74 -0
- data/app/views/items/new.html.erb +124 -0
- data/app/views/items/newpop.html.erb +58 -0
- data/app/views/items/show.html.erb +209 -0
- data/app/views/layouts/_amazon_ads.html.erb +55 -0
- data/app/views/layouts/_glossary_help_box.html.erb +43 -0
- data/app/views/layouts/_google_ads.html.erb +40 -0
- data/app/views/layouts/_language_select.html.erb +24 -0
- data/app/views/layouts/_login_controls.html.erb +24 -0
- data/app/views/layouts/_master_help.html.erb +24 -0
- data/app/views/layouts/_navigation_menu.html.erb +39 -0
- data/app/views/layouts/_search_box.html.erb +27 -0
- data/app/views/layouts/_status_msgs.html.erb +25 -0
- data/app/views/layouts/application.html.erb +67 -0
- data/app/views/layouts/base.html.erb +93 -0
- data/app/views/layouts/home.html.erb +67 -0
- data/app/views/layouts/popup.html.erb +23 -0
- data/assets/wontomedia-sample.rb +47 -0
- data/config/asset_packages.yml +44 -0
- data/config/boot.rb +110 -0
- data/config/cucumber.yml +65 -0
- data/config/database-mysql-development.yml +47 -0
- data/config/database-mysql.yml +26 -0
- data/config/environment.rb +94 -0
- data/config/environments/cucumber.rb +29 -0
- data/config/environments/development.rb +26 -0
- data/config/environments/production.rb +33 -0
- data/config/environments/test.rb +31 -0
- data/config/initializers/inflections.rb +19 -0
- data/config/initializers/mime_types.rb +14 -0
- data/config/initializers/new_rails_defaults.rb +26 -0
- data/config/locales/en.yml +14 -0
- data/config/routes.rb +37 -0
- data/db/fixtures/connections.yml +96 -0
- data/db/fixtures/items.yml +277 -0
- data/db/migrate/20090312212805_create_items.rb +31 -0
- data/db/migrate/20090406221320_create_connections.rb +32 -0
- data/db/migrate/20090411014503_add_type_for_item_subclasses.rb +29 -0
- data/db/migrate/20090415142152_rename_item_type.rb +31 -0
- data/db/migrate/20090518022918_rename_object_and_self.rb +33 -0
- data/db/migrate/20090529171442_add_flags_to_items.rb +27 -0
- data/db/migrate/20090529171508_add_flags_to_connections.rb +27 -0
- data/db/migrate/20090605213800_flags_columns_not_null.rb +29 -0
- data/db/migrate/20090605215028_flags_columns_default_zero.rb +29 -0
- data/db/schema.rb +30 -0
- data/default-custom/app/views/items/_home_extern_list.html.erb +32 -0
- data/default-custom/app/views/items/_home_introductory_text.html.erb +70 -0
- data/default-custom/app/views/items/home.html.erb +77 -0
- data/default-custom/public/images/logo.png +0 -0
- data/default-custom/public/images/logo.svg +74 -0
- data/default-custom/public/stylesheets/wm.css +301 -0
- data/doc/README.markdown +44 -0
- data/doc/README_FOR_APP +82 -0
- data/doc/customization.markdown +93 -0
- data/doc/scripts/rake-customize.markdown +83 -0
- data/lib/helpers/connection_helper.rb +41 -0
- data/lib/helpers/item_helper.rb +141 -0
- data/lib/helpers/tripple_navigation.rb +158 -0
- data/lib/tasks/cucumber.rake +83 -0
- data/lib/tasks/customize.rake +70 -0
- data/lib/tasks/db.rake +65 -0
- data/lib/tasks/javascript_testing_tasks.rake +176 -0
- data/public/404.html +50 -0
- data/public/422.html +50 -0
- data/public/500.html +53 -0
- data/public/dispatch.cgi +20 -0
- data/public/dispatch.fcgi +34 -0
- data/public/dispatch.rb +20 -0
- data/public/favicon.ico +0 -0
- data/public/images/blank_error_icon.png +0 -0
- data/public/images/blank_status_icon.png +0 -0
- data/public/images/error_error_icon.png +0 -0
- data/public/images/error_status_icon.png +0 -0
- data/public/images/good_status_icon.png +0 -0
- data/public/images/help_icon.png +0 -0
- data/public/images/twitter_icon.png +0 -0
- data/public/images/warn_error_icon.png +0 -0
- data/public/images/working_status_icon.gif +0 -0
- data/public/javascripts/application.js +56 -0
- data/public/javascripts/controls.js +963 -0
- data/public/javascripts/dragdrop.js +973 -0
- data/public/javascripts/effects.js +1128 -0
- data/public/javascripts/event.simulate.js +64 -0
- data/public/javascripts/fancybox.js +43 -0
- data/public/javascripts/forConnectionsForms.js +218 -0
- data/public/javascripts/forItemsForms.js +511 -0
- data/public/javascripts/itemCreatePopup.js +115 -0
- data/public/javascripts/itemTitleToName.js +119 -0
- data/public/javascripts/jquery.js +4376 -0
- data/public/javascripts/modalbox.js +502 -0
- data/public/javascripts/prototype.js +4320 -0
- data/public/javascripts/reconcileJQueryAndPrototype.js +19 -0
- data/public/robots.txt +7 -0
- data/public/stylesheets/blank.gif +0 -0
- data/public/stylesheets/fancy_close.png +0 -0
- data/public/stylesheets/fancy_loading.png +0 -0
- data/public/stylesheets/fancy_nav_left.png +0 -0
- data/public/stylesheets/fancy_nav_right.png +0 -0
- data/public/stylesheets/fancy_shadow_e.png +0 -0
- data/public/stylesheets/fancy_shadow_n.png +0 -0
- data/public/stylesheets/fancy_shadow_ne.png +0 -0
- data/public/stylesheets/fancy_shadow_nw.png +0 -0
- data/public/stylesheets/fancy_shadow_s.png +0 -0
- data/public/stylesheets/fancy_shadow_se.png +0 -0
- data/public/stylesheets/fancy_shadow_sw.png +0 -0
- data/public/stylesheets/fancy_shadow_w.png +0 -0
- data/public/stylesheets/fancy_title_left.png +0 -0
- data/public/stylesheets/fancy_title_main.png +0 -0
- data/public/stylesheets/fancy_title_over.png +0 -0
- data/public/stylesheets/fancy_title_right.png +0 -0
- data/public/stylesheets/fancybox.css +333 -0
- data/public/stylesheets/modalbox.css +110 -0
- data/public/stylesheets/scaffold.css +36 -0
- data/public/stylesheets/spinner.gif +0 -0
- data/script/about +4 -0
- data/script/console +3 -0
- data/script/cucumber +10 -0
- data/script/dbconsole +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/performance/request +3 -0
- data/script/plugin +3 -0
- data/script/process/inspector +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/vendor/plugins/asset_packager/CHANGELOG +122 -0
- data/vendor/plugins/asset_packager/README +178 -0
- data/vendor/plugins/asset_packager/Rakefile +22 -0
- data/vendor/plugins/asset_packager/about.yml +8 -0
- data/vendor/plugins/asset_packager/init.rb +2 -0
- data/vendor/plugins/asset_packager/install.rb +1 -0
- data/vendor/plugins/asset_packager/lib/jsmin.rb +205 -0
- data/vendor/plugins/asset_packager/lib/synthesis/asset_package.rb +212 -0
- data/vendor/plugins/asset_packager/lib/synthesis/asset_package_helper.rb +39 -0
- data/vendor/plugins/asset_packager/tasks/asset_packager_tasks.rake +23 -0
- data/vendor/plugins/asset_packager/test/asset_package_helper_development_test.rb +100 -0
- data/vendor/plugins/asset_packager/test/asset_package_helper_production_test.rb +140 -0
- data/vendor/plugins/asset_packager/test/asset_packager_test.rb +92 -0
- data/vendor/plugins/asset_packager/test/asset_packages.yml +20 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/application.js +2 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/bar.js +4 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/controls.js +815 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/dragdrop.js +913 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/effects.js +958 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/foo.js +4 -0
- data/vendor/plugins/asset_packager/test/assets/javascripts/prototype.js +2006 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/bar.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/foo.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/header.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/screen.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/subdir/bar.css +16 -0
- data/vendor/plugins/asset_packager/test/assets/stylesheets/subdir/foo.css +16 -0
- metadata +265 -0
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,205 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# jsmin.rb 2007-07-20
|
3
|
+
# Author: Uladzislau Latynski
|
4
|
+
# This work is a translation from C to Ruby of jsmin.c published by
|
5
|
+
# Douglas Crockford. Permission is hereby granted to use the Ruby
|
6
|
+
# version under the same conditions as the jsmin.c on which it is
|
7
|
+
# based.
|
8
|
+
#
|
9
|
+
# /* jsmin.c
|
10
|
+
# 2003-04-21
|
11
|
+
#
|
12
|
+
# Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
13
|
+
#
|
14
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
15
|
+
# this software and associated documentation files (the "Software"), to deal in
|
16
|
+
# the Software without restriction, including without limitation the rights to
|
17
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
18
|
+
# of the Software, and to permit persons to whom the Software is furnished to do
|
19
|
+
# so, subject to the following conditions:
|
20
|
+
#
|
21
|
+
# The above copyright notice and this permission notice shall be included in all
|
22
|
+
# copies or substantial portions of the Software.
|
23
|
+
#
|
24
|
+
# The Software shall be used for Good, not Evil.
|
25
|
+
#
|
26
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
28
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
29
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
31
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
32
|
+
# SOFTWARE.
|
33
|
+
|
34
|
+
EOF = -1
|
35
|
+
$theA = ""
|
36
|
+
$theB = ""
|
37
|
+
|
38
|
+
# isAlphanum -- return true if the character is a letter, digit, underscore,
|
39
|
+
# dollar sign, or non-ASCII character
|
40
|
+
def isAlphanum(c)
|
41
|
+
return false if !c || c == EOF
|
42
|
+
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
|
43
|
+
(c >= 'A' && c <= 'Z') || c == '_' || c == '$' ||
|
44
|
+
c == '\\' || c[0] > 126)
|
45
|
+
end
|
46
|
+
|
47
|
+
# get -- return the next character from stdin. Watch out for lookahead. If
|
48
|
+
# the character is a control character, translate it to a space or linefeed.
|
49
|
+
def get()
|
50
|
+
c = $stdin.getc
|
51
|
+
return EOF if(!c)
|
52
|
+
c = c.chr
|
53
|
+
return c if (c >= " " || c == "\n" || c.unpack("c") == EOF)
|
54
|
+
return "\n" if (c == "\r")
|
55
|
+
return " "
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get the next character without getting it.
|
59
|
+
def peek()
|
60
|
+
lookaheadChar = $stdin.getc
|
61
|
+
$stdin.ungetc(lookaheadChar)
|
62
|
+
return lookaheadChar.chr
|
63
|
+
end
|
64
|
+
|
65
|
+
# mynext -- get the next character, excluding comments.
|
66
|
+
# peek() is used to see if a '/' is followed by a '/' or '*'.
|
67
|
+
def mynext()
|
68
|
+
c = get
|
69
|
+
if (c == "/")
|
70
|
+
if(peek == "/")
|
71
|
+
while(true)
|
72
|
+
c = get
|
73
|
+
if (c <= "\n")
|
74
|
+
return c
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
if(peek == "*")
|
79
|
+
get
|
80
|
+
while(true)
|
81
|
+
case get
|
82
|
+
when "*"
|
83
|
+
if (peek == "/")
|
84
|
+
get
|
85
|
+
return " "
|
86
|
+
end
|
87
|
+
when EOF
|
88
|
+
raise "Unterminated comment"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
return c
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# action -- do something! What you do is determined by the argument: 1
|
98
|
+
# Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B.
|
99
|
+
# (Delete A). 3 Get the next B. (Delete B). action treats a string as a
|
100
|
+
# single character. Wow! action recognizes a regular expression if it is
|
101
|
+
# preceded by ( or , or =.
|
102
|
+
def action(a)
|
103
|
+
if(a==1)
|
104
|
+
$stdout.write $theA
|
105
|
+
end
|
106
|
+
if(a==1 || a==2)
|
107
|
+
$theA = $theB
|
108
|
+
if ($theA == "\'" || $theA == "\"")
|
109
|
+
while (true)
|
110
|
+
$stdout.write $theA
|
111
|
+
$theA = get
|
112
|
+
break if ($theA == $theB)
|
113
|
+
raise "Unterminated string literal" if ($theA <= "\n")
|
114
|
+
if ($theA == "\\")
|
115
|
+
$stdout.write $theA
|
116
|
+
$theA = get
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
if(a==1 || a==2 || a==3)
|
122
|
+
$theB = mynext
|
123
|
+
if ($theB == "/" && ($theA == "(" || $theA == "," || $theA == "=" ||
|
124
|
+
$theA == ":" || $theA == "[" || $theA == "!" ||
|
125
|
+
$theA == "&" || $theA == "|" || $theA == "?" ||
|
126
|
+
$theA == "{" || $theA == "}" || $theA == ";" ||
|
127
|
+
$theA == "\n"))
|
128
|
+
$stdout.write $theA
|
129
|
+
$stdout.write $theB
|
130
|
+
while (true)
|
131
|
+
$theA = get
|
132
|
+
if ($theA == "/")
|
133
|
+
break
|
134
|
+
elsif ($theA == "\\")
|
135
|
+
$stdout.write $theA
|
136
|
+
$theA = get
|
137
|
+
elsif ($theA <= "\n")
|
138
|
+
raise "Unterminated RegExp Literal"
|
139
|
+
end
|
140
|
+
$stdout.write $theA
|
141
|
+
end
|
142
|
+
$theB = mynext
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# jsmin -- Copy the input to the output, deleting the characters which are
|
148
|
+
# insignificant to JavaScript. Comments will be removed. Tabs will be
|
149
|
+
# replaced with spaces. Carriage returns will be replaced with linefeeds.
|
150
|
+
# Most spaces and linefeeds will be removed.
|
151
|
+
def jsmin
|
152
|
+
$theA = "\n"
|
153
|
+
action(3)
|
154
|
+
while ($theA != EOF)
|
155
|
+
case $theA
|
156
|
+
when " "
|
157
|
+
if (isAlphanum($theB))
|
158
|
+
action(1)
|
159
|
+
else
|
160
|
+
action(2)
|
161
|
+
end
|
162
|
+
when "\n"
|
163
|
+
case ($theB)
|
164
|
+
when "{","[","(","+","-"
|
165
|
+
action(1)
|
166
|
+
when " "
|
167
|
+
action(3)
|
168
|
+
else
|
169
|
+
if (isAlphanum($theB))
|
170
|
+
action(1)
|
171
|
+
else
|
172
|
+
action(2)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
else
|
176
|
+
case ($theB)
|
177
|
+
when " "
|
178
|
+
if (isAlphanum($theA))
|
179
|
+
action(1)
|
180
|
+
else
|
181
|
+
action(3)
|
182
|
+
end
|
183
|
+
when "\n"
|
184
|
+
case ($theA)
|
185
|
+
when "}","]",")","+","-","\"","\\", "'", '"'
|
186
|
+
action(1)
|
187
|
+
else
|
188
|
+
if (isAlphanum($theA))
|
189
|
+
action(1)
|
190
|
+
else
|
191
|
+
action(3)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
else
|
195
|
+
action(1)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
ARGV.each do |anArg|
|
202
|
+
$stdout.write "// #{anArg}\n"
|
203
|
+
end
|
204
|
+
|
205
|
+
jsmin
|
@@ -0,0 +1,212 @@
|
|
1
|
+
module Synthesis
|
2
|
+
class AssetPackage
|
3
|
+
|
4
|
+
# class variables
|
5
|
+
@@asset_packages_yml = $asset_packages_yml ||
|
6
|
+
(File.exists?("#{RAILS_ROOT}/config/asset_packages.yml") ? YAML.load_file("#{RAILS_ROOT}/config/asset_packages.yml") : nil)
|
7
|
+
|
8
|
+
# singleton methods
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def merge_environments=(environments)
|
12
|
+
@@merge_environments = environments
|
13
|
+
end
|
14
|
+
|
15
|
+
def merge_environments
|
16
|
+
@@merge_environments ||= ["production"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_path(path)
|
20
|
+
/^(?:(.*)\/)?([^\/]+)$/.match(path).to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_by_type(asset_type)
|
24
|
+
@@asset_packages_yml[asset_type].map { |p| self.new(asset_type, p) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_by_target(asset_type, target)
|
28
|
+
package_hash = @@asset_packages_yml[asset_type].find {|p| p.keys.first == target }
|
29
|
+
package_hash ? self.new(asset_type, package_hash) : nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_by_source(asset_type, source)
|
33
|
+
path_parts = parse_path(source)
|
34
|
+
package_hash = @@asset_packages_yml[asset_type].find do |p|
|
35
|
+
key = p.keys.first
|
36
|
+
p[key].include?(path_parts[2]) && (parse_path(key)[1] == path_parts[1])
|
37
|
+
end
|
38
|
+
package_hash ? self.new(asset_type, package_hash) : nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def targets_from_sources(asset_type, sources)
|
42
|
+
package_names = Array.new
|
43
|
+
sources.each do |source|
|
44
|
+
package = find_by_target(asset_type, source) || find_by_source(asset_type, source)
|
45
|
+
package_names << (package ? package.current_file : source)
|
46
|
+
end
|
47
|
+
package_names.uniq
|
48
|
+
end
|
49
|
+
|
50
|
+
def sources_from_targets(asset_type, targets)
|
51
|
+
source_names = Array.new
|
52
|
+
targets.each do |target|
|
53
|
+
package = find_by_target(asset_type, target)
|
54
|
+
source_names += (package ? package.sources.collect do |src|
|
55
|
+
package.target_dir.gsub(/^(.+)$/, '\1/') + src
|
56
|
+
end : target.to_a)
|
57
|
+
end
|
58
|
+
source_names.uniq
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_all
|
62
|
+
@@asset_packages_yml.keys.each do |asset_type|
|
63
|
+
@@asset_packages_yml[asset_type].each { |p| self.new(asset_type, p).build }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete_all
|
68
|
+
@@asset_packages_yml.keys.each do |asset_type|
|
69
|
+
@@asset_packages_yml[asset_type].each { |p| self.new(asset_type, p).delete_previous_build }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_yml
|
74
|
+
unless File.exists?("#{RAILS_ROOT}/config/asset_packages.yml")
|
75
|
+
asset_yml = Hash.new
|
76
|
+
|
77
|
+
asset_yml['javascripts'] = [{"base" => build_file_list("#{RAILS_ROOT}/public/javascripts", "js")}]
|
78
|
+
asset_yml['stylesheets'] = [{"base" => build_file_list("#{RAILS_ROOT}/public/stylesheets", "css")}]
|
79
|
+
|
80
|
+
File.open("#{RAILS_ROOT}/config/asset_packages.yml", "w") do |out|
|
81
|
+
YAML.dump(asset_yml, out)
|
82
|
+
end
|
83
|
+
|
84
|
+
log "config/asset_packages.yml example file created!"
|
85
|
+
log "Please reorder files under 'base' so dependencies are loaded in correct order."
|
86
|
+
else
|
87
|
+
log "config/asset_packages.yml already exists. Aborting task..."
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
# instance methods
|
94
|
+
attr_accessor :asset_type, :target, :target_dir, :sources
|
95
|
+
|
96
|
+
def initialize(asset_type, package_hash)
|
97
|
+
target_parts = self.class.parse_path(package_hash.keys.first)
|
98
|
+
@target_dir = target_parts[1].to_s
|
99
|
+
@target = target_parts[2].to_s
|
100
|
+
@sources = package_hash[package_hash.keys.first]
|
101
|
+
@asset_type = asset_type
|
102
|
+
@asset_path = ($asset_base_path ? "#{$asset_base_path}/" : "#{RAILS_ROOT}/public/") +
|
103
|
+
"#{@asset_type}#{@target_dir.gsub(/^(.+)$/, '/\1')}"
|
104
|
+
@extension = get_extension
|
105
|
+
@file_name = "#{@target}_packaged.#{@extension}"
|
106
|
+
@full_path = File.join(@asset_path, @file_name)
|
107
|
+
end
|
108
|
+
|
109
|
+
def package_exists?
|
110
|
+
File.exists?(@full_path)
|
111
|
+
end
|
112
|
+
|
113
|
+
def current_file
|
114
|
+
build unless package_exists?
|
115
|
+
|
116
|
+
path = @target_dir.gsub(/^(.+)$/, '\1/')
|
117
|
+
"#{path}#{@target}_packaged"
|
118
|
+
end
|
119
|
+
|
120
|
+
def build
|
121
|
+
delete_previous_build
|
122
|
+
create_new_build
|
123
|
+
end
|
124
|
+
|
125
|
+
def delete_previous_build
|
126
|
+
File.delete(@full_path) if File.exists?(@full_path)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
def create_new_build
|
131
|
+
new_build_path = "#{@asset_path}/#{@target}_packaged.#{@extension}"
|
132
|
+
if File.exists?(new_build_path)
|
133
|
+
log "Latest version already exists: #{new_build_path}"
|
134
|
+
else
|
135
|
+
File.open(new_build_path, "w") {|f| f.write(compressed_file) }
|
136
|
+
log "Created #{new_build_path}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def merged_file
|
141
|
+
merged_file = ""
|
142
|
+
@sources.each {|s|
|
143
|
+
File.open("#{@asset_path}/#{s}.#{@extension}", "r") { |f|
|
144
|
+
merged_file += f.read + "\n"
|
145
|
+
}
|
146
|
+
}
|
147
|
+
merged_file
|
148
|
+
end
|
149
|
+
|
150
|
+
def compressed_file
|
151
|
+
case @asset_type
|
152
|
+
when "javascripts" then compress_js(merged_file)
|
153
|
+
when "stylesheets" then compress_css(merged_file)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def compress_js(source)
|
158
|
+
jsmin_path = "#{RAILS_ROOT}/vendor/plugins/asset_packager/lib"
|
159
|
+
tmp_path = "#{RAILS_ROOT}/tmp/#{@target}_packaged"
|
160
|
+
|
161
|
+
# write out to a temp file
|
162
|
+
File.open("#{tmp_path}_uncompressed.js", "w") {|f| f.write(source) }
|
163
|
+
|
164
|
+
# compress file with JSMin library
|
165
|
+
`ruby #{jsmin_path}/jsmin.rb <#{tmp_path}_uncompressed.js >#{tmp_path}_compressed.js \n`
|
166
|
+
|
167
|
+
# read it back in and trim it
|
168
|
+
result = ""
|
169
|
+
File.open("#{tmp_path}_compressed.js", "r") { |f| result += f.read.strip }
|
170
|
+
|
171
|
+
# delete temp files if they exist
|
172
|
+
File.delete("#{tmp_path}_uncompressed.js") if File.exists?("#{tmp_path}_uncompressed.js")
|
173
|
+
File.delete("#{tmp_path}_compressed.js") if File.exists?("#{tmp_path}_compressed.js")
|
174
|
+
|
175
|
+
result
|
176
|
+
end
|
177
|
+
|
178
|
+
def compress_css(source)
|
179
|
+
source.gsub!(/\s+/, " ") # collapse space
|
180
|
+
source.gsub!(/\/\*(.*?)\*\//, "") # remove comments - caution, might want to remove this if using css hacks
|
181
|
+
source.gsub!(/\} /, "}\n") # add line breaks
|
182
|
+
source.gsub!(/\n$/, "") # remove last break
|
183
|
+
source.gsub!(/ \{ /, " {") # trim inside brackets
|
184
|
+
source.gsub!(/; \}/, "}") # trim inside brackets
|
185
|
+
source
|
186
|
+
end
|
187
|
+
|
188
|
+
def get_extension
|
189
|
+
case @asset_type
|
190
|
+
when "javascripts" then "js"
|
191
|
+
when "stylesheets" then "css"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def log(message)
|
196
|
+
self.class.log(message)
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.log(message)
|
200
|
+
puts message
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.build_file_list(path, extension)
|
204
|
+
re = Regexp.new(".#{extension}\\z")
|
205
|
+
file_list = Dir.new(path).entries.delete_if { |x| ! (x =~ re) }.map {|x| x.chomp(".#{extension}")}
|
206
|
+
# reverse javascript entries so prototype comes first on a base rails app
|
207
|
+
file_list.reverse! if extension == "js"
|
208
|
+
file_list
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Synthesis
|
2
|
+
module AssetPackageHelper
|
3
|
+
|
4
|
+
def should_merge?
|
5
|
+
AssetPackage.merge_environments.include?(RAILS_ENV)
|
6
|
+
end
|
7
|
+
|
8
|
+
def javascript_include_merged(*sources)
|
9
|
+
options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
|
10
|
+
|
11
|
+
if sources.include?(:defaults)
|
12
|
+
sources = sources[0..(sources.index(:defaults))] +
|
13
|
+
['prototype', 'effects', 'dragdrop', 'controls'] +
|
14
|
+
(File.exists?("#{RAILS_ROOT}/public/javascripts/application.js") ? ['application'] : []) +
|
15
|
+
sources[(sources.index(:defaults) + 1)..sources.length]
|
16
|
+
sources.delete(:defaults)
|
17
|
+
end
|
18
|
+
|
19
|
+
sources.collect!{|s| s.to_s}
|
20
|
+
sources = (should_merge? ?
|
21
|
+
AssetPackage.targets_from_sources("javascripts", sources) :
|
22
|
+
AssetPackage.sources_from_targets("javascripts", sources))
|
23
|
+
|
24
|
+
sources.collect {|source| javascript_include_tag(source, options) }.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def stylesheet_link_merged(*sources)
|
28
|
+
options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
|
29
|
+
|
30
|
+
sources.collect!{|s| s.to_s}
|
31
|
+
sources = (should_merge? ?
|
32
|
+
AssetPackage.targets_from_sources("stylesheets", sources) :
|
33
|
+
AssetPackage.sources_from_targets("stylesheets", sources))
|
34
|
+
|
35
|
+
sources.collect { |source| stylesheet_link_tag(source, options) }.join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|