js_erb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -40,14 +40,25 @@ inside the yml file (e.g. <%= var %>).
40
40
 
41
41
  At the end set javascript_include_tag (add javascript files into the <head>).
42
42
 
43
- == JsErb with Jammit
43
+ == Javascript HTML Templates & Translations
44
+
45
+ JsErb will, in addition to javascript source files, create a javascript file with translations
46
+ and javascript file with HTML templates. You can access them in anywhere in your javascript like
47
+
48
+ # Access transations
49
+ alert( i18n.t('welcome') );
50
+
51
+ # Access template
52
+ alert( jserb.v('users.user') );
53
+
54
+ == JsErb With Jammit
44
55
 
45
56
  Best practice is to use a packager to optimize project's javascript and stylesheets. You can
46
57
  easily connect JsErb plugin with {Jammit}[http://documentcloud.github.com/jammit/] assets
47
58
  packager. To integrate JsErb with Jammit you simply define JsErb's generated compiled files
48
59
  (at RAILS/public/javascripts/compiled) in to Jammit's assets.yml file.
49
60
 
50
- == JsErb caching
61
+ == JsErb Caching
51
62
 
52
63
  The plugin will always compile files in the development or testing environment. In other
53
64
  environments (e.g. production) it will compile files only if the compiled directory is
@@ -54,9 +54,9 @@ module JsErb
54
54
  def compile_locales
55
55
  Dir.glob("#{JsErb.config['path']['locales']}/*.js.yml").each do |file|
56
56
  name = File.basename(file, '.js.yml')
57
- content = YAML.load(ERB.new(File.read(file)).result).to_json
57
+ content = YAML.load(ERB.new(File.read(file)).result)
58
58
  File.open(File.join(JsErb.config['path']['compiled'], 'locales', "#{name}.js"), "wb") do |f|
59
- f.write("var i18n = #{content};")
59
+ f.write("window.i18n = {t:function(key){for(var i in i18n.$){return i18n.$[i][key]}}, $:#{content.to_json} };")
60
60
  end
61
61
  end
62
62
  end
@@ -84,7 +84,7 @@ module JsErb
84
84
  end
85
85
 
86
86
  File.open(File.join(JsErb.config['path']['compiled'], 'views', 'jserb.js'), "wb") do |f|
87
- f.write("var jserb = #{list.to_json};")
87
+ f.write("window.jserb = { v:function(key){return jserb.$[key]}, $:#{list.to_json} };")
88
88
  end
89
89
  end
90
90
 
@@ -2,7 +2,7 @@ module JsErb
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_erb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kristijan Sedlak