web_optimizer 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +2 -0
- data/.ruby-version +2 -0
- data/README.md +20 -3
- data/data/en.js.coffee +12 -0
- data/lib/common/google_translator.rb +14 -0
- data/lib/web_optimizer/version.rb +1 -1
- data/lib/web_stuff.rb +1 -0
- data/lib/web_stuff/angular_locale_translations.rb +57 -0
- data/lib/web_stuff/less_to_scss.rb +4 -2
- data/lib/web_stuff/yaml_translations.rb +1 -11
- data/tmp.rb +3 -0
- data/web_optimizer.gemspec +2 -0
- metadata +42 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdefc7859805a916418b280fafaffc876381be3e
|
4
|
+
data.tar.gz: 78184a0411b91f1ebd3bfcbdc71f35a8ee379cc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a24a1bd060d310e029676bb64682394bf86abcaca24f5e4c38f3f5f1dcb61c7e5a2a40f164410c05a24339cc92efd65dc8ac3a40c5767b91d596763cb3105bb4
|
7
|
+
data.tar.gz: 14e81b2fe2df6817e89886e80ae5265abbb368023ca6f20a90ab527dae9686f4999dc38862b60184ad1b704fcdc233384555c65db76ba6a00e2a9c1c8bfa79a0
|
data/.ruby-gemset
ADDED
data/.ruby-version
ADDED
data/README.md
CHANGED
@@ -19,21 +19,38 @@ vo.mita.ov at gmail.com if you need help or want to contribute
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
|
22
|
+
|
23
|
+
**Compress Stuffs**
|
23
24
|
```
|
24
25
|
WebOptimizer.compress_css(dir, ignore_paths=[])
|
25
26
|
WebOptimizer.compress_js(dir, ignore_paths=[])
|
26
27
|
WebOptimizer.compress_img(dir, ignore_paths=[])
|
27
28
|
```
|
28
29
|
|
29
|
-
Translation Yaml files
|
30
|
+
**Translation Yaml files**
|
30
31
|
```
|
31
32
|
require "web_stuff"
|
32
33
|
dir_path = "/Users/tamvo/code/rails/minesweeper/config/locales"
|
33
34
|
WebStuff::YamlTranslations.translations_locale_dir(dir_path, "en", "it")
|
34
35
|
```
|
35
36
|
|
36
|
-
|
37
|
+
**Translation Angular Locale files**
|
38
|
+
|
39
|
+
- Sample `en.js.coffee` file:
|
40
|
+
|
41
|
+
```
|
42
|
+
@Locale ||= {}
|
43
|
+
@Locale.EN_LOCALES = {
|
44
|
+
banner_bitcoin: "Bitcoin"
|
45
|
+
}
|
46
|
+
```
|
47
|
+
|
48
|
+
```
|
49
|
+
require "web_stuff"
|
50
|
+
WebStuff::AngularLocaleTranslations.translations_locale_dir(dir_path, "en", "ja")
|
51
|
+
```
|
52
|
+
|
53
|
+
**Convert Less to Scss**
|
37
54
|
```
|
38
55
|
require "web_stuff"
|
39
56
|
WebStuff::LessToScss.convert("less_path")
|
data/data/en.js.coffee
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
@Locale ||= {}
|
2
|
+
@Locale.EN_LOCALES = {
|
3
|
+
banner_bitcoin: "Bitcoin"
|
4
|
+
banner_bitcoin_comma: "Bitcoin,"
|
5
|
+
banner_safe_reliable_easy: "Safe, Reliable, Easy"
|
6
|
+
banner_strong_encryption: "Quoine uses the strongest encryption technologies for communications and data storage. We have partnered with top security firms that provide only the best of breed in security solutions, resulting in a highly secure and reliable platform."
|
7
|
+
banner_secure_robust_simple: "Secure, Robust, Simple"
|
8
|
+
banner_ease_and_confidence: "Buy and sell bitcoin with ease and confidence on an exchange built and run by banking professionals with decades of combined experience. We have put in place the strictest processes in line with financial regulations in major financial hubs."
|
9
|
+
banner_for_professionals_individuals: "For Professionals & Individuals"
|
10
|
+
banner_from_scratch: "Quoine was designed and built from scratch by banking professionals for professionals and individuals. Quoine provides a modern user interface in line with the latest design standards, as well as a rich and easy-to-use toolset for individuals, frequent traders, and professionals."
|
11
|
+
}
|
12
|
+
|
@@ -27,6 +27,20 @@ module Common
|
|
27
27
|
json = JSON(result.body.match(/^\[(\[\[.*?\]\])/)[1])
|
28
28
|
json[0][0]
|
29
29
|
end
|
30
|
+
|
31
|
+
def self.standarize_translation(original, translation)
|
32
|
+
translation = translation.gsub(/\n/, "").gsub(/% s/, "%s").gsub(/ /, " ").
|
33
|
+
gsub(/< ?(\/?) (\w+) >/, '<\1\2>').gsub(/ ([\.,!?])( |$)/, '\1')
|
34
|
+
|
35
|
+
translation_data = translation.scan(/{ ?{.*?} ?}/)
|
36
|
+
original_data = original.scan(/{{.*?}}/)
|
37
|
+
if translation_data.present?
|
38
|
+
translation_data.each_with_index do |trans, index|
|
39
|
+
translation = translation.gsub(trans, original_data[index])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
translation
|
43
|
+
end
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
data/lib/web_stuff.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "active_support"
|
3
|
+
|
4
|
+
module WebStuff
|
5
|
+
extend Common::GoogleTranslator
|
6
|
+
|
7
|
+
module AngularLocaleTranslations
|
8
|
+
def self.translations_locale_dir(dir_path, from_locale, to_locale)
|
9
|
+
raise Exception.new("Invalid dir path") unless File.directory? dir_path
|
10
|
+
puts "translations_locale_dir"
|
11
|
+
|
12
|
+
Dir[File.join(dir_path, "**/*.#{from_locale}.js.coffee"), File.join(dir_path, "**/#{from_locale}.js.coffee")].each do |locale_path|
|
13
|
+
if File.basename(locale_path) == "#{from_locale}.js.coffee"
|
14
|
+
dest_file = File.join(dir_path, "#{to_locale}.js.coffee")
|
15
|
+
else
|
16
|
+
dest_file = File.join(dir_path, "#{File.basename(locale_path, ".#{from_locale}.js.coffee")}.#{to_locale}.js.coffee")
|
17
|
+
end
|
18
|
+
|
19
|
+
to_hash = File.exists?(dest_file) ? build_hash_from_locale_file(dest_file) : {}
|
20
|
+
from_hash = build_hash_from_locale_file(locale_path)
|
21
|
+
from_hash.each do |key, value|
|
22
|
+
next if to_hash[key].present?
|
23
|
+
translation = Common::GoogleTranslator.translate(value, from_locale, to_locale)
|
24
|
+
translation = Common::GoogleTranslator.standarize_translation(value, translation)
|
25
|
+
to_hash[key] = translation
|
26
|
+
end
|
27
|
+
puts to_hash
|
28
|
+
content = <<RUBY
|
29
|
+
@Locale ||= {}
|
30
|
+
@Locale.#{to_locale.upcase}_LOCALES = {
|
31
|
+
RUBY
|
32
|
+
to_hash.each do |key, value|
|
33
|
+
content += <<RUBY
|
34
|
+
# #{from_hash[key]}
|
35
|
+
#{key}: "#{value}"
|
36
|
+
|
37
|
+
RUBY
|
38
|
+
end
|
39
|
+
content += "}"
|
40
|
+
Common::Util.write_file(dest_file, content)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
def self.build_hash_from_locale_file(locale_path)
|
46
|
+
hash = {}
|
47
|
+
File.readlines(locale_path).each do |line|
|
48
|
+
next unless line.include?(":")
|
49
|
+
pair = line.split(":")
|
50
|
+
str = pair[1].match(/"(.*?)"$/)[1]
|
51
|
+
hash[pair[0][/[\w_]+/]] = str
|
52
|
+
end
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -5,8 +5,8 @@ module WebStuff
|
|
5
5
|
|
6
6
|
content = File.read(path)
|
7
7
|
content.gsub!(/@\{?(\w+)\}?/, '$\1')
|
8
|
-
content.gsub!(
|
9
|
-
content.gsub!(
|
8
|
+
content.gsub!(/^\.([\w\-]*)\s*\((.*)\)\s*\{/, '@mixin \1(\2){')
|
9
|
+
content.gsub!(/^\.([\w\-]*\(.*\)\s*;)/, '@include \1')
|
10
10
|
content.gsub!(/~"(.*)"/, '\#{\"\1\"}')
|
11
11
|
content.gsub!(/\$import +["\'](.*?)\.less["\']/, '@import "\1.scss"')
|
12
12
|
content.gsub!('$media', '@media')
|
@@ -14,6 +14,8 @@ module WebStuff
|
|
14
14
|
content.gsub!('$-o-', '@-o-')
|
15
15
|
content.gsub!('$-webkit-', '@-webkit-')
|
16
16
|
|
17
|
+
puts "Please check @arguments"
|
18
|
+
|
17
19
|
Common::Util.write_file(File.join(File.dirname(path), File.basename(path, ".*") + ".scss"), content)
|
18
20
|
end
|
19
21
|
end
|
@@ -33,17 +33,7 @@ module WebStuff
|
|
33
33
|
self.traverse_hash(value, from_locale, to_locale)
|
34
34
|
elsif value.is_a?(String)
|
35
35
|
translation = Common::GoogleTranslator.translate(value, from_locale, to_locale)
|
36
|
-
|
37
|
-
gsub(/< ?(\/?) (\w+) >/, '<\1\2>').gsub(/ ([\.,!?])( |$)/, '\1')
|
38
|
-
|
39
|
-
translation_data = translation.scan(/{ ?{.*?} ?}/)
|
40
|
-
value_data = value.scan(/{{.*?}}/)
|
41
|
-
if translation_data.present?
|
42
|
-
translation_data.each_with_index do |trans, index|
|
43
|
-
translation = translation.gsub(trans, value_data[index])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
hash[key] = translation
|
36
|
+
hash[key] = Common::GoogleTranslator.standarize_translation(value, translation)
|
47
37
|
end
|
48
38
|
end
|
49
39
|
end
|
data/tmp.rb
CHANGED
@@ -5,3 +5,6 @@ dir = "/Users/tamvo/code/lib/ruby/web_optimizer/data"; WebOptimizer.compress_css
|
|
5
5
|
dir = "/Users/tamvo/code/lib/ruby/web_optimizer/data"; WebOptimizer.compress_js(dir)
|
6
6
|
dir = "/Users/tamvo/code/lib/ruby/web_optimizer/data"; WebOptimizer.compress_img(dir)
|
7
7
|
|
8
|
+
dir_path = "/Users/tamvo/code/lib/me/web_optimizer/data"
|
9
|
+
WebStuff::AngularLocaleTranslations.translations_locale_dir(dir_path, "en", "ja")
|
10
|
+
|
data/web_optimizer.gemspec
CHANGED
metadata
CHANGED
@@ -1,41 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tam Vo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fileutils
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mechanize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
41
69
|
description: Compress all css file in specified dir with yuicompressor
|
@@ -45,7 +73,9 @@ executables: []
|
|
45
73
|
extensions: []
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-gemset"
|
78
|
+
- ".ruby-version"
|
49
79
|
- Gemfile
|
50
80
|
- LICENSE.txt
|
51
81
|
- README.md
|
@@ -54,6 +84,7 @@ files:
|
|
54
84
|
- data/animation.css.bak
|
55
85
|
- data/balance.js
|
56
86
|
- data/balance.js.bak
|
87
|
+
- data/en.js.coffee
|
57
88
|
- data/screenshot.png
|
58
89
|
- lib/common/google_translator.rb
|
59
90
|
- lib/common/mechanize_helper.rb
|
@@ -65,6 +96,7 @@ files:
|
|
65
96
|
- lib/web_optimizer/optimize_images.rb
|
66
97
|
- lib/web_optimizer/version.rb
|
67
98
|
- lib/web_stuff.rb
|
99
|
+
- lib/web_stuff/angular_locale_translations.rb
|
68
100
|
- lib/web_stuff/less_to_scss.rb
|
69
101
|
- lib/web_stuff/yaml_translations.rb
|
70
102
|
- tmp.rb
|
@@ -79,12 +111,12 @@ require_paths:
|
|
79
111
|
- lib
|
80
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
113
|
requirements:
|
82
|
-
- -
|
114
|
+
- - ">="
|
83
115
|
- !ruby/object:Gem::Version
|
84
116
|
version: '0'
|
85
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
118
|
requirements:
|
87
|
-
- -
|
119
|
+
- - ">="
|
88
120
|
- !ruby/object:Gem::Version
|
89
121
|
version: '0'
|
90
122
|
requirements: []
|
@@ -94,3 +126,4 @@ signing_key:
|
|
94
126
|
specification_version: 4
|
95
127
|
summary: Compress css, js and optimize images tools
|
96
128
|
test_files: []
|
129
|
+
has_rdoc:
|