haml_coffee_template 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ module HamlCoffeeTemplate
2
+ class Processor
3
+ def initialize(filename, &block)
4
+ @filename = filename
5
+ @source = block.call
6
+ end
7
+
8
+ def render(context, _empty_hash_wtf)
9
+ self.class.run(@filename, @source, context)
10
+ end
11
+
12
+ def self.run(filename, source, context)
13
+ compiler.template(context.logical_path, source)
14
+ rescue StandardError => e
15
+ STDOUT.puts("(#{name}) Failed to compile: #{filename}")
16
+ raise e
17
+ end
18
+
19
+ def self.call(input)
20
+ filename = input[:filename]
21
+ source = input[:data]
22
+ context = input[:environment].context_class.new(input)
23
+ result = run(filename, source, context)
24
+ context.metadata.merge(data: result)
25
+ end
26
+
27
+ def self.compiler
28
+ @compiler ||= Compiler.new
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ module HamlCoffeeTemplate
2
+ class Railtie < Rails::Railtie
3
+ initializer "haml_coffee_template.setup" do |app|
4
+ app.config.assets.configure do |env|
5
+ if env.respond_to?(:register_transformer)
6
+ env.register_mime_type "text/hamlc", extensions: [".hamlc"]
7
+ env.register_transformer "text/hamlc", "application/javascript", HamlCoffeeTemplate::Processor
8
+ end
9
+
10
+ if env.respond_to?(:register_engine)
11
+ args = [".hamlc", HamlCoffeeTemplate::Processor]
12
+ args << { mime_type: "text/hamlc", silence_deprecation: true } if Sprockets::VERSION.start_with?("3")
13
+ env.register_engine(*args)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module HamlCoffeeTemplate
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ var HamlCoffeeTemplate = (function() {
2
+ var Compiler = require('./haml-coffee');
3
+
4
+ return {
5
+ template: function (src, name, namespace, compilerOptions){
6
+ var compiler = new Compiler(compilerOptions);
7
+ compiler.parse(src);
8
+ return CoffeeScript.compile(compiler.render(name, namespace));
9
+ },
10
+ compile: function (src, compilerOptions){
11
+ var compiler = new Compiler(compilerOptions);
12
+ compiler.parse(src);
13
+ return CoffeeScript.compile(compiler.precompile(), {bare: true});
14
+ }
15
+ }
16
+ })();
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haml_coffee_template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Krists Ozols
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coffee-script
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sprockets
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - lib/haml_coffee_template.rb
49
+ - lib/haml_coffee_template/compiler.rb
50
+ - lib/haml_coffee_template/configuration.rb
51
+ - lib/haml_coffee_template/hamlcoffee.js
52
+ - lib/haml_coffee_template/processor.rb
53
+ - lib/haml_coffee_template/railtie.rb
54
+ - lib/haml_coffee_template/version.rb
55
+ - lib/haml_coffee_template/wrapper.js
56
+ homepage: https://github.com/krists/haml_coffee_template
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.0.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Haml + CoffeeScript template adapter for the Rails asset pipeline
79
+ test_files: []