serve 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/VERSION +1 -1
- data/lib/serve/project.rb +2 -0
- data/lib/serve/view_helpers.rb +105 -9
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/serve/project.rb
CHANGED
data/lib/serve/view_helpers.rb
CHANGED
@@ -178,7 +178,7 @@ module Serve #:nodoc:
|
|
178
178
|
end
|
179
179
|
|
180
180
|
def image(name, options = {})
|
181
|
-
image_tag(
|
181
|
+
image_tag(ensure_path(ensure_extension(name, 'png'), 'images'), options)
|
182
182
|
end
|
183
183
|
|
184
184
|
def javascript_tag(content = nil, html_options = {})
|
@@ -193,8 +193,7 @@ module Serve #:nodoc:
|
|
193
193
|
end
|
194
194
|
|
195
195
|
def link_to_function(name, *args, &block)
|
196
|
-
html_options =
|
197
|
-
html_options = args.pop if args.last.is_a? Hash
|
196
|
+
html_options = extract_options!(args)
|
198
197
|
function = args[0] || ''
|
199
198
|
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
|
200
199
|
href = html_options[:href] || '#'
|
@@ -243,6 +242,61 @@ module Serve #:nodoc:
|
|
243
242
|
content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{email_address}#{extras}" })
|
244
243
|
end
|
245
244
|
end
|
245
|
+
|
246
|
+
# Generates JavaScript script tags for the sources given as arguments.
|
247
|
+
#
|
248
|
+
# If the .js extension is not given, it will be appended to the source.
|
249
|
+
#
|
250
|
+
# Examples
|
251
|
+
# javascript_include_tag 'application' # =>
|
252
|
+
# <script src="/javascripts/application.js" type="text/javascript" />
|
253
|
+
#
|
254
|
+
# javascript_include_tag 'https://cdn/jquery.js' # =>
|
255
|
+
# <script src="https://cdn/jquery.js" type="text/javascript" />
|
256
|
+
#
|
257
|
+
# javascript_include_tag 'application', 'books' # =>
|
258
|
+
# <script src="/javascripts/application.js" type="text/javascript" />
|
259
|
+
# <script src="/javascripts/books.js" type="text/javascript" />
|
260
|
+
#
|
261
|
+
def javascript_include_tag(*sources)
|
262
|
+
options = extract_options!(sources)
|
263
|
+
|
264
|
+
sources.map do |source|
|
265
|
+
content_tag('script', '', {
|
266
|
+
'type' => 'text/javascript',
|
267
|
+
'src' => ensure_path(ensure_extension(source, 'js'), 'javascripts')
|
268
|
+
}.merge(options))
|
269
|
+
end.join("\n")
|
270
|
+
end
|
271
|
+
|
272
|
+
# Generates stylesheet link tags for the sources given as arguments.
|
273
|
+
#
|
274
|
+
# If the .css extension is not given, it will be appended to the source.
|
275
|
+
#
|
276
|
+
# Examples
|
277
|
+
# stylesheet_link_tag 'screen' # =>
|
278
|
+
# <link href="/stylesheets/screen.css" media="screen" rel="stylesheet" type="text/css" />
|
279
|
+
#
|
280
|
+
# stylesheet_link_tag 'print', :media => 'print' # =>
|
281
|
+
# <link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css" />
|
282
|
+
#
|
283
|
+
# stylesheet_link_tag 'application', 'books', 'authors' # =>
|
284
|
+
# <link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
|
285
|
+
# <link href="/stylesheets/books.css" media="screen" rel="stylesheet" type="text/css" />
|
286
|
+
# <link href="/stylesheets/authors.css" media="screen" rel="stylesheet" type="text/css" />
|
287
|
+
#
|
288
|
+
def stylesheet_link_tag(*sources)
|
289
|
+
options = extract_options!(sources)
|
290
|
+
|
291
|
+
sources.map do |source|
|
292
|
+
tag('link', {
|
293
|
+
'rel' => 'stylesheet',
|
294
|
+
'type' => 'text/css',
|
295
|
+
'media' => 'screen',
|
296
|
+
'href' => ensure_path(ensure_extension(source, 'css'), 'stylesheets')
|
297
|
+
}.merge(options))
|
298
|
+
end.join("\n")
|
299
|
+
end
|
246
300
|
|
247
301
|
private
|
248
302
|
|
@@ -267,13 +321,55 @@ module Serve #:nodoc:
|
|
267
321
|
" #{attrs.sort * ' '}" unless attrs.empty?
|
268
322
|
end
|
269
323
|
end
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
324
|
+
|
325
|
+
# Ensures a proper extension is appended to the filename.
|
326
|
+
#
|
327
|
+
# If a URI with the http or https scheme name is given, it is assumed
|
328
|
+
# to be absolute and will not be altered.
|
329
|
+
#
|
330
|
+
# Examples
|
331
|
+
# ensure_extension('screen', 'css') => 'screen.css'
|
332
|
+
# ensure_extension('screen.css', 'css') => 'screen.css'
|
333
|
+
# ensure_extension('jquery.min', 'js') => 'jquery.min.js'
|
334
|
+
# ensure_extension('https://cdn/jquery', 'js') => 'https://cdn/jquery'
|
335
|
+
#
|
336
|
+
def ensure_extension(source, extension)
|
337
|
+
if source =~ /^https?:/ || source.end_with?(".#{extension}")
|
338
|
+
return source
|
339
|
+
end
|
340
|
+
|
341
|
+
"#{source}.#{extension}"
|
342
|
+
end
|
343
|
+
|
344
|
+
# Ensures the proper path to the given source.
|
345
|
+
#
|
346
|
+
# If the source begins at the root of the public directory or is a URI
|
347
|
+
# with the http or https scheme name, it is assumed to be absolute and
|
348
|
+
# will not be altered.
|
349
|
+
#
|
350
|
+
# Examples
|
351
|
+
# ensure_path('screen.css', 'stylesheets') => '/stylesheets/screen.css'
|
352
|
+
# ensure_path('/screen.css', 'stylesheets') => '/screen.css'
|
353
|
+
# ensure_path('http://cdn/jquery.js', 'javascripts') => 'http://cdn/jquery.js'
|
354
|
+
#
|
355
|
+
def ensure_path(source, path)
|
356
|
+
if source =~ /^(\/|https?)/
|
357
|
+
return source
|
276
358
|
end
|
359
|
+
|
360
|
+
File.join('', path, source)
|
361
|
+
end
|
362
|
+
|
363
|
+
# Returns a hash of options if they exist at the end of an array.
|
364
|
+
#
|
365
|
+
# This is useful when working with splats.
|
366
|
+
#
|
367
|
+
# Examples
|
368
|
+
# extract_options!([1, 2, { :name => 'sunny' }]) => { :name => 'sunny' }
|
369
|
+
# extract_options!([1, 2, 3]) => {}
|
370
|
+
#
|
371
|
+
def extract_options!(array)
|
372
|
+
array.last.instance_of?(Hash) ? array.pop : {}
|
277
373
|
end
|
278
374
|
end
|
279
375
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John W. Long
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-06-07 00:00:00 -04:00
|
21
21
|
default_executable: serve
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|