clean_shaved 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ require 'execjs'
2
+ require 'digest/md5'
3
+
4
+ require 'clean_shaved/rails/clean_shaved_engine'
5
+ require 'clean_shaved/helpers'
6
+
7
+ module CleanShaved
8
+ def CleanShaved.compile(name, tmpl)
9
+ CleanShaved.cache[Digest::MD5.hexdigest("#{name}:#{tmpl}").to_sym] ||=
10
+ CleanShaved.context.call("Handlebars.precompile", tmpl)
11
+ end
12
+
13
+ def CleanShaved.config
14
+ @config ||= Config.new(true)
15
+ end
16
+
17
+ private
18
+ HANDLEBAR_PATH = File.expand_path("../../app/assets/javascripts/handlebars-1.0.rc.1.js", __FILE__)
19
+
20
+ def CleanShaved.context
21
+ @context ||= begin
22
+ src = IO.read(HANDLEBAR_PATH)
23
+ ExecJS.compile(src)
24
+ end
25
+ end
26
+
27
+ def CleanShaved.cache
28
+ @cache ||= {}
29
+ end
30
+
31
+ class Config < Struct.new(:compile)
32
+ def compile?
33
+ compile
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ require 'tagz'
2
+
3
+ module CleanShaved
4
+ module Helpers
5
+ include Tagz
6
+
7
+ def template_for(*args, &block)
8
+ name = args.first
9
+ options = args.extract_options!.to_options!
10
+
11
+ tmpl = capture(&block)
12
+
13
+ if CleanShaved.config.compile?
14
+ script_ type: 'text/javascript' do
15
+ "Handlebars.templates['#{name}'] = Handlebars.template(#{CleanShaved.compile(name, tmpl)});"
16
+ .gsub(/\s+/, ' ')
17
+ end
18
+ else
19
+ options[:type] ||= "text/x-handlebars-template"
20
+ options[:class] ||= "template"
21
+ options[:name] ||= name
22
+
23
+ script_(options) do
24
+ tmpl
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ require 'clean_shaved/helpers'
2
+
3
+ module CleanShaved
4
+ module Rails
5
+ class CleanShavedEngine < ::Rails::Engine
6
+ isolate_namespace CleanShaved
7
+
8
+ initializer "clean_shaved.assets.precompile" do |app|
9
+ app.config.assets.precompile += %w(clean_shaved.js)
10
+ end
11
+
12
+ initializer "clean_shaved.helpers" do
13
+ ActionView::Base.send :include, Helpers
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clean_shaved
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Frederic Jean
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Insert CleanShaved description.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - app/assets/javascripts/clean_shaved.js
21
+ - app/assets/javascripts/handlebars-1.0.rc.1.js
22
+ - lib/clean_shaved/helpers.rb
23
+ - lib/clean_shaved/rails/clean_shaved_engine.rb
24
+ - lib/clean_shaved.rb
25
+ - MIT-LICENSE
26
+ - Rakefile
27
+ - Gemfile
28
+ - README.md
29
+ homepage:
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Insert CleanShaved summary.
53
+ test_files: []