spar 0.2.7 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.md +272 -1
  2. data/bin/spar +30 -1
  3. data/lib/spar.rb +128 -7
  4. data/lib/spar/assets/404.jpg +0 -0
  5. data/lib/spar/assets/500.jpg +0 -0
  6. data/lib/spar/cli.rb +75 -22
  7. data/lib/spar/compiled_asset.rb +90 -0
  8. data/lib/spar/compiler.rb +74 -0
  9. data/lib/spar/compressor.rb +18 -0
  10. data/lib/spar/deployers/cloudfront_deployer.rb +33 -0
  11. data/lib/spar/deployers/deployer.rb +26 -0
  12. data/lib/spar/deployers/local_deployer.rb +15 -0
  13. data/lib/spar/deployers/s3_deployer.rb +75 -0
  14. data/lib/spar/directive_processor.rb +36 -0
  15. data/lib/spar/exceptions.rb +330 -0
  16. data/lib/spar/generators/templates/{README → base/README} +0 -0
  17. data/lib/spar/generators/templates/base/config.yml +12 -0
  18. data/lib/spar/generators/templates/pages/haml/app/pages/index.html.haml +11 -0
  19. data/lib/spar/generators/templates/pages/html/app/pages/index.html +16 -0
  20. data/lib/spar/generators/templates/{app/assets/javascripts/javascript.js.coffee → scripts/coffee/app/javascripts/application.js.coffee} +6 -3
  21. data/lib/spar/generators/templates/scripts/js/app/javascripts/application.js +11 -0
  22. data/lib/spar/generators/templates/styles/css/app/stylesheets/application.css +18 -0
  23. data/lib/spar/generators/templates/{app/assets → styles/sass/app}/stylesheets/application.css.sass +8 -4
  24. data/lib/spar/helpers.rb +31 -102
  25. data/lib/spar/not_found.rb +64 -0
  26. data/lib/spar/rewrite.rb +29 -0
  27. data/lib/spar/static.rb +46 -0
  28. data/lib/spar/tasks.rb +8 -13
  29. data/lib/spar/version.rb +1 -1
  30. metadata +261 -66
  31. data/lib/spar/assets.rb +0 -78
  32. data/lib/spar/base.rb +0 -54
  33. data/lib/spar/css_compressor.rb +0 -17
  34. data/lib/spar/deployer.rb +0 -198
  35. data/lib/spar/generators/application.rb +0 -42
  36. data/lib/spar/generators/templates/Gemfile +0 -3
  37. data/lib/spar/generators/templates/Rakefile +0 -8
  38. data/lib/spar/generators/templates/app/views/index.haml +0 -7
  39. data/lib/spar/generators/templates/config.ru +0 -9
  40. data/lib/spar/generators/templates/config/application.rb +0 -12
  41. data/lib/spar/generators/templates/script/server +0 -1
  42. data/lib/spar/static_compiler.rb +0 -91
@@ -0,0 +1,36 @@
1
+ module Spar
2
+
3
+ class DirectiveProcessor < Sprockets::Processor
4
+
5
+ def evaluate(context, locals, &block)
6
+ @result = data
7
+
8
+ process_methods
9
+
10
+ @result
11
+ end
12
+
13
+ protected
14
+
15
+ def process_methods
16
+ @result.gsub!(/\[\{(.*?)\}\]/) do
17
+ command = $1.strip
18
+ case command
19
+ when /^path_to\((?<file_name>.*)\)$/
20
+ Spar::Helpers.path_to($~[:file_name])
21
+ when /^javascript_include_tag\((?<file_names>.*)\)$/
22
+ Spar::Helpers.javascript_include_tag(*($~[:file_names]).split(',').map(&:strip))
23
+ when /^stylesheet_link_tag\((?<file_names>.*)\)$/
24
+ Spar::Helpers.stylesheet_link_tag(*($~[:file_names]).split(',').map(&:strip))
25
+ else
26
+ if variable = Spar.settings[command]
27
+ variable
28
+ else
29
+ raise "Could not find a value for: '#{command}'"
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,330 @@
1
+ require 'rack/showexceptions'
2
+
3
+ module Spar
4
+
5
+ class Exceptions < Rack::ShowExceptions
6
+ @@eats_errors = Object.new
7
+ def @@eats_errors.flush(*) end
8
+ def @@eats_errors.puts(*) end
9
+
10
+ def initialize(app)
11
+ @app = app
12
+ @template = ERB.new(TEMPLATE)
13
+ end
14
+
15
+ def call(env)
16
+ @app.call(env)
17
+ rescue Exception => e
18
+ errors, env["rack.errors"] = env["rack.errors"], @@eats_errors
19
+
20
+ content_type = "text/html"
21
+ body = pretty(env, e)
22
+
23
+ env["rack.errors"] = errors
24
+
25
+ [500,
26
+ {"Content-Type" => content_type,
27
+ "Content-Length" => Rack::Utils.bytesize(body.join).to_s},
28
+ body]
29
+ end
30
+
31
+ private
32
+
33
+ def frame_class(frame)
34
+ if frame.filename =~ /lib\/sinatra.*\.rb/
35
+ "framework"
36
+ elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
37
+ frame.filename =~ /\/bin\/(\w+)$/
38
+ "system"
39
+ else
40
+ "app"
41
+ end
42
+ end
43
+
44
+ TEMPLATE = <<-HTML # :nodoc:
45
+ <!DOCTYPE html>
46
+ <html>
47
+ <head>
48
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
49
+ <title><%=h exception.class %> at <%=h path %></title>
50
+
51
+ <script type="text/javascript">
52
+ //<!--
53
+ function toggle(id) {
54
+ var pre = document.getElementById("pre-" + id);
55
+ var post = document.getElementById("post-" + id);
56
+ var context = document.getElementById("context-" + id);
57
+
58
+ if (pre.style.display == 'block') {
59
+ pre.style.display = 'none';
60
+ post.style.display = 'none';
61
+ context.style.background = "none";
62
+ } else {
63
+ pre.style.display = 'block';
64
+ post.style.display = 'block';
65
+ context.style.background = "#fffed9";
66
+ }
67
+ }
68
+
69
+ function toggleBacktrace(){
70
+ var bt = document.getElementById("backtrace");
71
+ var toggler = document.getElementById("expando");
72
+
73
+ if (bt.className == 'condensed') {
74
+ bt.className = 'expanded';
75
+ toggler.innerHTML = "(condense)";
76
+ } else {
77
+ bt.className = 'condensed';
78
+ toggler.innerHTML = "(expand)";
79
+ }
80
+ }
81
+ //-->
82
+ </script>
83
+
84
+ <style type="text/css" media="screen">
85
+ * {margin: 0; padding: 0; border: 0; outline: 0;}
86
+ div.clear {clear: both;}
87
+ body {background: #EEEEEE; margin: 0; padding: 0;
88
+ font-family: 'Lucida Grande', 'Lucida Sans Unicode',
89
+ 'Garuda';}
90
+ code {font-family: 'Lucida Console', monospace;
91
+ font-size: 12px;}
92
+ li {height: 18px;}
93
+ ul {list-style: none; margin: 0; padding: 0;}
94
+ ol:hover {cursor: pointer;}
95
+ ol li {white-space: pre;}
96
+ #explanation {font-size: 12px; color: #666666;
97
+ margin: 20px 0 0 100px;}
98
+ /* WRAP */
99
+ #wrap {width: 1000px; background: #FFFFFF; margin: 0 auto;
100
+ padding: 30px 50px 20px 50px;
101
+ border-left: 1px solid #DDDDDD;
102
+ border-right: 1px solid #DDDDDD;}
103
+ /* HEADER */
104
+ #header {margin: 0 auto 25px auto;}
105
+ #header img {float: left;}
106
+ #header #summary {float: left; margin: 38px 0 0 20px; width:610px;
107
+ font-family: 'Lucida Grande', 'Lucida Sans Unicode';}
108
+ h1 {margin: 0; font-size: 36px; color: #BE292B;}
109
+ h2 {margin: 0; font-size: 22px; color: #333333;}
110
+ #header ul {margin: 0; font-size: 12px; color: #666666;}
111
+ #header ul li strong{color: #444444;}
112
+ #header ul li {display: inline; padding: 0 10px;}
113
+ #header ul li.first {padding-left: 0;}
114
+ #header ul li.last {border: 0; padding-right: 0;}
115
+ /* BODY */
116
+ #backtrace,
117
+ #get,
118
+ #post,
119
+ #cookies,
120
+ #rack {width: 980px; margin: 0 auto 10px auto;}
121
+ p#nav {float: right; font-size: 14px;}
122
+ /* BACKTRACE */
123
+ a#expando {float: left; padding-left: 5px; color: #666666;
124
+ font-size: 14px; text-decoration: none; cursor: pointer;}
125
+ a#expando:hover {text-decoration: underline;}
126
+ h3 {float: left; width: 100px; margin-bottom: 10px;
127
+ color: #BE292B; font-size: 14px; font-weight: bold;}
128
+ #nav a {color: #666666; text-decoration: none; padding: 0 5px;}
129
+ #backtrace li.frame-info {background: #f7f7f7; padding-left: 10px;
130
+ font-size: 12px; color: #333333;}
131
+ #backtrace ul {list-style-position: outside; border: 1px solid #E9E9E9;
132
+ border-bottom: 0;}
133
+ #backtrace ol {width: 920px; margin-left: 50px;
134
+ font: 10px 'Lucida Console', monospace; color: #666666;}
135
+ #backtrace ol li {border: 0; border-left: 1px solid #E9E9E9;
136
+ padding: 2px 0;}
137
+ #backtrace ol code {font-size: 10px; color: #555555; padding-left: 5px;}
138
+ #backtrace-ul li {border-bottom: 1px solid #E9E9E9; height: auto;
139
+ padding: 3px 0;}
140
+ #backtrace-ul .code {padding: 6px 0 4px 0;}
141
+ #backtrace.condensed .system,
142
+ #backtrace.condensed .framework {display:none;}
143
+ /* REQUEST DATA */
144
+ p.no-data {padding-top: 2px; font-size: 12px; color: #666666;}
145
+ table.req {width: 980px; text-align: left; font-size: 12px;
146
+ color: #666666; padding: 0; border-spacing: 0;
147
+ border: 1px solid #EEEEEE; border-bottom: 0;
148
+ border-left: 0;
149
+ clear:both}
150
+ table.req tr th {padding: 2px 10px; font-weight: bold;
151
+ background: #F7F7F7; border-bottom: 1px solid #EEEEEE;
152
+ border-left: 1px solid #EEEEEE;}
153
+ table.req tr td {padding: 2px 20px 2px 10px;
154
+ border-bottom: 1px solid #EEEEEE;
155
+ border-left: 1px solid #EEEEEE;}
156
+ /* HIDE PRE/POST CODE AT START */
157
+ .pre-context,
158
+ .post-context {display: none;}
159
+
160
+ table td.code {width:750px}
161
+ table td.code div {width:750px;overflow:hidden}
162
+ </style>
163
+ </head>
164
+ <body>
165
+ <div id="wrap">
166
+ <div id="header">
167
+ <img src="<%= env['SCRIPT_NAME'] %>/__spar__/500.jpg" alt="application error" height="213" width="366" />
168
+ <div id="summary">
169
+ <h1><strong><%=h exception.class %></strong> at <strong><%=h path %>
170
+ </strong></h1>
171
+ <h2><%=h exception.message.gsub("#{Spar.root.to_s}/", '') %></h2>
172
+ <ul>
173
+ <li class="first"><strong>file:</strong> <code>
174
+ <%=h frames.first.filename.split("/").last %></code></li>
175
+ <li><strong>location:</strong> <code><%=h frames.first.function %>
176
+ </code></li>
177
+ <li class="last"><strong>line:
178
+ </strong> <%=h frames.first.lineno %></li>
179
+ </ul>
180
+ </div>
181
+ <div class="clear"></div>
182
+ </div>
183
+
184
+ <div id="backtrace" class='condensed'>
185
+ <h3>BACKTRACE</h3>
186
+ <p><a href="#" id="expando"
187
+ onclick="toggleBacktrace(); return false">(expand)</a></p>
188
+ <p id="nav"><strong>JUMP TO:</strong>
189
+ <a href="#get-info">GET</a>
190
+ <a href="#post-info">POST</a>
191
+ <a href="#cookie-info">COOKIES</a>
192
+ <a href="#env-info">ENV</a>
193
+ </p>
194
+ <div class="clear"></div>
195
+
196
+ <ul id="backtrace-ul">
197
+
198
+ <% id = 1 %>
199
+ <% frames.each do |frame| %>
200
+ <% if frame.context_line && frame.context_line != "#" %>
201
+
202
+ <li class="frame-info <%= frame_class(frame) %>">
203
+ <code><%=h frame.filename %></code> in
204
+ <code><strong><%=h frame.function %></strong></code>
205
+ </li>
206
+
207
+ <li class="code <%= frame_class(frame) %>">
208
+ <% if frame.pre_context %>
209
+ <ol start="<%=h frame.pre_context_lineno + 1 %>"
210
+ class="pre-context" id="pre-<%= id %>"
211
+ onclick="toggle(<%= id %>);">
212
+ <% frame.pre_context.each do |line| %>
213
+ <li class="pre-context-line"><code><%=h line %></code></li>
214
+ <% end %>
215
+ </ol>
216
+ <% end %>
217
+
218
+ <ol start="<%= frame.lineno %>" class="context" id="<%= id %>"
219
+ onclick="toggle(<%= id %>);">
220
+ <li class="context-line" id="context-<%= id %>"><code><%=
221
+ h frame.context_line %></code></li>
222
+ </ol>
223
+
224
+ <% if frame.post_context %>
225
+ <ol start="<%=h frame.lineno + 1 %>" class="post-context"
226
+ id="post-<%= id %>" onclick="toggle(<%= id %>);">
227
+ <% frame.post_context.each do |line| %>
228
+ <li class="post-context-line"><code><%=h line %></code></li>
229
+ <% end %>
230
+ </ol>
231
+ <% end %>
232
+ <div class="clear"></div>
233
+ </li>
234
+
235
+ <% end %>
236
+
237
+ <% id += 1 %>
238
+ <% end %>
239
+
240
+ </ul>
241
+ </div> <!-- /BACKTRACE -->
242
+
243
+ <div id="get">
244
+ <h3 id="get-info">GET</h3>
245
+ <% if req.GET and not req.GET.empty? %>
246
+ <table class="req">
247
+ <tr>
248
+ <th>Variable</th>
249
+ <th>Value</th>
250
+ </tr>
251
+ <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
252
+ <tr>
253
+ <td><%=h key %></td>
254
+ <td class="code"><div><%=h val.inspect %></div></td>
255
+ </tr>
256
+ <% } %>
257
+ </table>
258
+ <% else %>
259
+ <p class="no-data">No GET data.</p>
260
+ <% end %>
261
+ <div class="clear"></div>
262
+ </div> <!-- /GET -->
263
+
264
+ <div id="post">
265
+ <h3 id="post-info">POST</h3>
266
+ <% if req.POST and not req.POST.empty? %>
267
+ <table class="req">
268
+ <tr>
269
+ <th>Variable</th>
270
+ <th>Value</th>
271
+ </tr>
272
+ <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
273
+ <tr>
274
+ <td><%=h key %></td>
275
+ <td class="code"><div><%=h val.inspect %></div></td>
276
+ </tr>
277
+ <% } %>
278
+ </table>
279
+ <% else %>
280
+ <p class="no-data">No POST data.</p>
281
+ <% end %>
282
+ <div class="clear"></div>
283
+ </div> <!-- /POST -->
284
+
285
+ <div id="cookies">
286
+ <h3 id="cookie-info">COOKIES</h3>
287
+ <% unless req.cookies.empty? %>
288
+ <table class="req">
289
+ <tr>
290
+ <th>Variable</th>
291
+ <th>Value</th>
292
+ </tr>
293
+ <% req.cookies.each { |key, val| %>
294
+ <tr>
295
+ <td><%=h key %></td>
296
+ <td class="code"><div><%=h val.inspect %></div></td>
297
+ </tr>
298
+ <% } %>
299
+ </table>
300
+ <% else %>
301
+ <p class="no-data">No cookie data.</p>
302
+ <% end %>
303
+ <div class="clear"></div>
304
+ </div> <!-- /COOKIES -->
305
+
306
+ <div id="rack">
307
+ <h3 id="env-info">Rack ENV</h3>
308
+ <table class="req">
309
+ <tr>
310
+ <th>Variable</th>
311
+ <th>Value</th>
312
+ </tr>
313
+ <% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
314
+ <tr>
315
+ <td><%=h key %></td>
316
+ <td class="code"><div><%=h val %></div></td>
317
+ </tr>
318
+ <% } %>
319
+ </table>
320
+ <div class="clear"></div>
321
+ </div> <!-- /RACK ENV -->
322
+
323
+ <p id="explanation">You're seeing this error because you have
324
+ enabled the <code>show_exceptions</code> setting.</p>
325
+ </div> <!-- /WRAP -->
326
+ </body>
327
+ </html>
328
+ HTML
329
+ end
330
+ end
@@ -0,0 +1,12 @@
1
+ default:
2
+ debug: true
3
+ digest: false
4
+ compress: false
5
+
6
+ development:
7
+ debug: true
8
+
9
+ production:
10
+ debug: false
11
+ digest: true
12
+ compress: true
@@ -0,0 +1,11 @@
1
+ !!! Strict
2
+ %html
3
+ %head
4
+ %title Spar App
5
+ [{ stylesheet_link_tag(application) }]
6
+ %body
7
+ %h1
8
+ Nice app!
9
+ %h2
10
+ Point LiveReload to the directory of this project if you want to use it. No extensions or JS required.
11
+ [{ javascript_include_tag(application) }]
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html>
3
+ <head>
4
+ <title>Spar App</title>
5
+ [{ stylesheet_link_tag(application) }]
6
+ </head>
7
+ <body>
8
+ <h1>
9
+ Nice app!
10
+ </h1>
11
+ <h2>
12
+ Point LiveReload to the directory of this project if you want to use it. No extensions or JS required.
13
+ </h2>
14
+ [{ javascript_include_tag(application) }]
15
+ </body>
16
+ </html>
@@ -1,10 +1,13 @@
1
+ #= deploy
2
+
1
3
  # This is a manifest file that'll be compiled into application.js, which will include all the files
2
4
  # listed below.
3
5
 
4
- # Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- # or vendor/assets/javascripts of gems, if any, can be referenced here using a relative path.
6
+ # Any JavaScript/Coffee file within this directory or vendor/javascripts can be referenced here using a relative path.
6
7
 
7
8
  # It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
9
  # the compiled file.
9
10
 
10
- # = require_tree .
11
+ #= require_tree .
12
+
13
+
@@ -0,0 +1,11 @@
1
+ //= deploy
2
+
3
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
4
+ // listed below.
5
+
6
+ // Any JavaScript/Coffee file within this directory or vendor/javascripts can be referenced here using a relative path.
7
+
8
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
9
+ // the compiled file.
10
+
11
+ //= require_tree .
@@ -0,0 +1,18 @@
1
+ /*= deploy */
2
+
3
+ /*
4
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
5
+ * listed below.
6
+ *
7
+ * Any CSS and SASS file within this directory or vendor/stylesheets can be referenced here using a relative path.
8
+ *
9
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
10
+ * compiled file, but it's generally better to create a new file per style scope.
11
+ *
12
+ *= require_self
13
+ *= require_tree .
14
+ */
15
+
16
+ body {
17
+ background: white;
18
+ }