Skip to content
This repository
Browse code

Auto-remove the comments from the source when packaging

  • Loading branch information...
commit dfe11af4a9679aac2e12892333b83a1aedecafb8 1 parent 7626f81
Jon Leighton authored

Showing 2 changed files with 15 additions and 7 deletions. Show diff stats Hide diff stats

  1. +12 4 Rakefile
  2. +3 3 jquery.date_input.js
16 Rakefile
@@ -11,10 +11,11 @@ class PackageGenerator
11 11 def generate
12 12 delete_previous
13 13 copy_files
14   - write_header
  14 + process_code
15 15 pack_js
16 16 minify_js
17 17 compress
  18 + ensure
18 19 clean_up
19 20 end
20 21
@@ -24,13 +25,20 @@ class PackageGenerator
24 25
25 26 def copy_files
26 27 FileUtils.mkdir package_dir
27   - FileUtils.cp root_files("date_input.css", "LICENCE", "README", "CHANGELOG", "NOTES"), package_dir
  28 + FileUtils.cp root_files("date_input.css", "LICENCE", "README", "CHANGELOG"), package_dir
28 29 end
29 30
30   - def write_header
  31 + def process_code
  32 + code = File.read(root_file(plugin_file))
  33 +
  34 + code.gsub!(/\/\/[^\n]+/, "") # Remove any other '//' comments (without deleting the line)
  35 + code.gsub!(/\/\*.+\*\//m, "") # Remove '/* */' comments
  36 +
  37 + code.gsub!(/(\n +\n)( +\n)+/) { $1 } # Remove any multiple empty lines
  38 +
31 39 open(package_file(plugin_file), "w") do |file|
32 40 file << header
33   - file << File.read(root_file(plugin_file))
  41 + file << code
34 42 end
35 43 end
36 44
6 jquery.date_input.js
@@ -292,10 +292,10 @@ DateInput.prototype = {
292 292 return (end - start) / 86400000;
293 293 },
294 294
295   - // changeDayTo: Given a date, move along the date line in the given direction until we reach the
296   - // desired day of week.
297   -
298 295 /*
  296 + changeDayTo: Given a date, move along the date line in the given direction until we reach the
  297 + desired day of week.
  298 +
299 299 The maths is a bit complex, here's an explanation.
300 300
301 301 Think of a continuous repeating number line like:

0 comments on commit dfe11af

Please sign in to comment.
Something went wrong with that request. Please try again.