uki 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/bin/uki +1 -1
  3. data/lib/uki/include_js.rb +37 -7
  4. metadata +8 -9
  5. data/.gitignore +0 -7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
data/bin/uki CHANGED
@@ -118,7 +118,7 @@ command :build do |c|
118
118
  c.syntax = 'uki build [file1 [, file2]]'
119
119
  c.summary = 'Build current project'
120
120
  c.description = 'Merges and compresses javascript files.
121
- Merges all include() and include_css() in js files. Merged output
121
+ Merges all include() and include_text() in js files. Merged output
122
122
  is processed through google clousure compiler. Supports .js and .html
123
123
  files as parameters.
124
124
 
@@ -1,9 +1,13 @@
1
1
  require 'json'
2
+ require 'base64'
2
3
 
3
4
  module Uki
4
5
 
5
- INCLUDE_REGEXP = %r{((?:^|\n)[^\n]\W|^|\n)\s*include\s*\(\s*['"]([^"']+)["']\s*\)(?:\s*;)?(.*?\r?\n|$)}
6
- INCLUDE_CSS_REGEXP = %r{include_css\s*\(\s*['"]([^"']+)["']\s*\)}
6
+ INCLUDE_REGEXP = %r{(^|^[^\n]*[^\w\n])include\s*\(\s*['"]([^"']+)["']\s*\)(?:\s*;)?(.*?\r?\n|$)}
7
+ INCLUDE_TEXT_REGEXP = %r{include_(?:text|css)\s*\(\s*['"]([^"']+)["']\s*\)}
8
+
9
+ BACKGROUND_URL_REGEXP = %r{url\s*\(\s*['"]?([^"'\)]+)["']?\s*\)}
10
+ DATA_URI_REGEXP = %r{/\*!\s*data:([^\s\*]*)\s*\*/['"]?([^"']+)['"]}
7
11
 
8
12
  #
9
13
  # Preprocesses include() calls in js files
@@ -18,7 +22,14 @@ module Uki
18
22
  end
19
23
 
20
24
  included[path] = true
21
- code.gsub(INCLUDE_REGEXP) do |match|
25
+ code.gsub(INCLUDE_TEXT_REGEXP) do |match|
26
+ include_text File.join(base, $1), &block
27
+
28
+ end.gsub(DATA_URI_REGEXP) do |match|
29
+ uri = to_data_uri File.join(base, $2), $1
30
+ "'#{uri}'"
31
+
32
+ end.gsub(INCLUDE_REGEXP) do |match|
22
33
  if $1.include? '//' # include commented out
23
34
  match
24
35
  else
@@ -29,16 +40,35 @@ module Uki
29
40
  $1 + $3
30
41
  end
31
42
  end
32
- end.gsub(INCLUDE_CSS_REGEXP) do |match|
33
- include_css File.join(base, $1), &block
34
43
  end
35
44
  end
36
45
 
37
- def self.include_css path, &block
46
+ def self.to_data_uri path, type = nil
47
+ if !type || type.empty?
48
+ ext = File.extname(path)
49
+ if ext == '.png'
50
+ type = 'image/png'
51
+ elsif ext == '.gif'
52
+ type = 'image/gif'
53
+ else
54
+ type = 'text/plain'
55
+ end
56
+ end
57
+ "data:#{type};base64," + Base64.encode64(File.read(path)).gsub("\n", '')
58
+ end
59
+
60
+ def self.include_text path, &block
38
61
  code = if block_given?
39
62
  yield path
40
63
  else
41
- File.read(path)
64
+ File.read(path).gsub(BACKGROUND_URL_REGEXP) do |match|
65
+ url = $1;
66
+ unless url =~ %r{^(/|\w+://)}
67
+ filename = File.join(File.dirname(path), url);
68
+ url = self.to_data_uri(filename)
69
+ end
70
+ "url(#{url})";
71
+ end
42
72
  end
43
73
  (code || '').to_json
44
74
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uki
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 21
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Vladimir Kolesnikov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-18 00:00:00 +04:00
18
+ date: 2011-01-05 00:00:00 -08:00
19
19
  default_executable: uki
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,7 +73,6 @@ extensions: []
73
73
  extra_rdoc_files:
74
74
  - LICENSE
75
75
  files:
76
- - .gitignore
77
76
  - .gitmodules
78
77
  - LICENSE
79
78
  - Rakefile
@@ -437,8 +436,8 @@ homepage: http://github.com/voloko/uki
437
436
  licenses: []
438
437
 
439
438
  post_install_message:
440
- rdoc_options:
441
- - --charset=UTF-8
439
+ rdoc_options: []
440
+
442
441
  require_paths:
443
442
  - lib
444
443
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -462,7 +461,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
462
461
  requirements: []
463
462
 
464
463
  rubyforge_project:
465
- rubygems_version: 1.3.7
464
+ rubygems_version: 1.4.1
466
465
  signing_key:
467
466
  specification_version: 3
468
467
  summary: uki development tools
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *.log
2
- *.pid
3
- tmp*
4
- .DS_Store
5
- *~
6
- pkg/
7
- *.swp