hamljsx 0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hamljsx.rb +53 -0
  3. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa2b2763cb274fb0bbb3311ccc51ed6a2f357a82
4
+ data.tar.gz: 3e26671904156fb077a841ba6571f05e0739272f
5
+ SHA512:
6
+ metadata.gz: 7c0e1abd33a13bbd6972c5b3e437f5dc6331f874f970d602a94410008fd12929c7ff2dce3fbceea0a25a674f5f83d147980bfb95fe491697e1c96f119bb83d01
7
+ data.tar.gz: 9c3ce9359180616e5d53a4584e77111c75e0dfe556e2a5f5dcd2d280f3cf8cc8bafb77baac705296147778d1f69495d4e9f57f20dda281d108ff06509e025acf
@@ -0,0 +1,53 @@
1
+ require 'tilt'
2
+ require 'rails'
3
+
4
+ class HamlJsxTemplate < Tilt::Template
5
+ MARKER_START = "(~"
6
+ MARKER_END = "~)"
7
+
8
+ def prepare
9
+ Haml::Options.defaults[:format] = :xhtml
10
+ end
11
+
12
+ def evaluate(context, locals, &block)
13
+ result = ""
14
+ offset = 0
15
+
16
+ while true
17
+ idx_start = @data.index(MARKER_START, offset)
18
+ if idx_start
19
+ idx_start += 1
20
+ idx_end = @data.index(MARKER_END, idx_start + MARKER_END.length)-1
21
+
22
+ result += @data[offset..(idx_start-1)]
23
+ offset = idx_end + MARKER_END.length
24
+
25
+ haml = @data[(idx_start + MARKER_START.length)..(idx_end-1)]
26
+ haml.gsub!(/\{/,"'{")
27
+ haml.gsub!(/\}/,"}'")
28
+ first_indent = haml.match(/\s*/)[0]
29
+ haml.gsub!(/^#{first_indent}/,"")
30
+
31
+ haml.gsub!(/^.$/,"%div")
32
+
33
+ html = Haml::Engine.new(haml).render
34
+ html.gsub!("class=","className=")
35
+ html.gsub!(/\'{/,"{")
36
+ html.gsub!(/\}\'/,"}")
37
+
38
+ result += html
39
+ else
40
+ result += @data[offset..-1]
41
+ break
42
+ end
43
+ end
44
+
45
+ result
46
+ end
47
+ end
48
+
49
+ class HamlJsx < Rails::Railtie
50
+ initializer "hamljsx.add_template" do
51
+ Rails.application.assets.register_engine '.haml', HamlJsxTemplate
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hamljsx
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Dan Hassin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Inline Haml in JSX just like HTML, using (~ and ~) delimeters. Rather
14
+ limited still.
15
+ email:
16
+ - danhassin@mac.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/hamljsx.rb
22
+ homepage: http://rubygems.org/gems/hamljsx
23
+ licenses:
24
+ - license.md
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.6
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Use Haml with JSX!
46
+ test_files: []