hamlit-block 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e4499cd2e559e092beed6aa9c5ad3e259b1ccfa
4
- data.tar.gz: 1729f636eb93b49ec840b13cb3da49a338d635a2
3
+ metadata.gz: 1abd0ce08b2e4ff7e417ff0d4b3b2b1fabfcf073
4
+ data.tar.gz: 1088a092796c1cb6b49531f15dce6555ec177006
5
5
  SHA512:
6
- metadata.gz: e70812d43c13940a1ae0e98f47344a70fa84d61403cefbd7b157ec686872d5b6b422c702084338651c25df3abf41e070fb78a042b6dd5eecc64859080b6cd87e
7
- data.tar.gz: 6fb701cfde8af3e2f2b62f5023e5fe91511414b0a3cafdc30aa243c23faaf63bc1fbf6b6c8c2bde3c1b9c7fed011faa47ab4f3c8c9019dbf688ee4ee1c9c03ef
6
+ metadata.gz: 27f0f46ae8b05d9178975192cc837ab6f48244434e5bdd95979449dbb0d0aa52cd2334267ce006d1b9932e39f17464f5ad79eb7b8fe7d5a164643fd40280f7a7
7
+ data.tar.gz: 67a602550adaa07b2626597781845067f908b736ce3fcdf3554c5585a2c8e4ec72aa269987097ee182b309f19282bf5bc0c4c6dec7226e8881ab8528b4621d91
@@ -1,10 +1,15 @@
1
1
  require "hamlit"
2
+ require "hamlit/block/compiler_extension"
2
3
  require "hamlit/block/script_compiler_extension"
4
+ require "hamlit/block/silent_script_compiler_extension"
3
5
  require "hamlit/block/version"
4
6
 
5
7
  module Hamlit
6
8
  class Compiler
9
+ prepend Block::CompilerExtension
10
+
7
11
  ScriptCompiler.send(:prepend, Block::ScriptCompilerExtension)
12
+ SilentScriptCompiler.send(:prepend, Block::SilentScriptCompilerExtension)
8
13
  end
9
14
 
10
15
  # Maybe hamlit-block's users expect this. This is Haml's default.
@@ -0,0 +1,11 @@
1
+ module Hamlit
2
+ module Block
3
+ # Set identity for SilentScriptCompilerExtension
4
+ module CompilerExtension
5
+ def initialize(*)
6
+ super
7
+ @silent_script_compiler.identity = @script_compiler.identity
8
+ end
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,8 @@ module Hamlit
2
2
  module Block
3
3
  # Suppress block's internal rendering result and pass it to [:capture, ...].
4
4
  module ScriptCompilerExtension
5
+ attr_reader :identity
6
+
5
7
  def compile_script_assign(var, node, &block)
6
8
  if node.children.empty?
7
9
  super
@@ -0,0 +1,26 @@
1
+ module Hamlit
2
+ module Block
3
+ # Suppress block's internal rendering result and pass it to [:capture, ...].
4
+ # if it script is `do .. end` block
5
+ module SilentScriptCompilerExtension
6
+ attr_writer :identity
7
+
8
+ BLOCK_REGEX = /do(\s*\|\s*[^\|]*\s*\|)?\s*\z/
9
+
10
+ def compile_with_children(node, &block)
11
+ if node.value[:text] =~ BLOCK_REGEX
12
+ [:multi,
13
+ [:block, node.value[:text],
14
+ [:multi,
15
+ [:newline],
16
+ [:capture, @identity.generate, yield(node)],
17
+ ],
18
+ ]
19
+ ]
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Hamlit
2
2
  module Block
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit-block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-12 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hamlit
@@ -118,7 +118,9 @@ files:
118
118
  - bin/setup
119
119
  - hamlit-block.gemspec
120
120
  - lib/hamlit/block.rb
121
+ - lib/hamlit/block/compiler_extension.rb
121
122
  - lib/hamlit/block/script_compiler_extension.rb
123
+ - lib/hamlit/block/silent_script_compiler_extension.rb
122
124
  - lib/hamlit/block/version.rb
123
125
  homepage: https://github.com/hamlit/hamlit-block
124
126
  licenses:
@@ -140,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
142
  version: '0'
141
143
  requirements: []
142
144
  rubyforge_project:
143
- rubygems_version: 2.4.5.1
145
+ rubygems_version: 2.5.1
144
146
  signing_key:
145
147
  specification_version: 4
146
148
  summary: Hamlit extension to support capturing via yield