ejx 1.0 → 1.1

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
  SHA256:
3
- metadata.gz: 2dc481f36010e82885f2b6ea60a4f13bb4e6c9c4b823ee6899fd02ce12650942
4
- data.tar.gz: 7262002c9a7cb0b3ce87def1d77911e45d6a3e85dde2ae4bfe3fa41aff0f7741
3
+ metadata.gz: c5e3997ce1ac9e0edc1de2f0046b0b6a088bdaae849e05278c86223a4e4d620f
4
+ data.tar.gz: db78cf1549960d7264a1eb001fd1999c94a911f9f8e00aaa721e1d9471bbfd72
5
5
  SHA512:
6
- metadata.gz: 58f1139b43dcf0205a43619b0f167460d27bd5a75b1708cb4b9497887b8696c7aa5489df61ac89da4e17b3df22a460d3b9fa4ca2f8ce2e5ed6b5fa6c30ca41a4
7
- data.tar.gz: 8cd338246eb063e0156504252c83216fc003f507af94655b3f383984e98831ff5e01ddcc669d6c80e85fa84b8a47888170c97e1ccf11e28b0a80be6f23606142
6
+ metadata.gz: 3770f88b9741b78be7d90ce40d865821b6e0f71f4a6ee3cb48c018c93b81436f31df47b83fd0b9143935439f8ddfb594eebdfda1724487c44f4b015af024d74a
7
+ data.tar.gz: 873581ec37a56a0ffa9a4b9c0e44f9f9aa632b41419f2ad8e67a8033a22bc9e6915d74cb0827e7ebe15028d4a9a7ac2ddcc669a28caa15b61eb4bfd4ba3cebea
@@ -1,17 +1,26 @@
1
+ function insertBefore(el, items) {
2
+ items.forEach((i) => {
3
+ if ( Array.isArray(i) ) {
4
+ insertBefore(el, i);
5
+ } else if (i instanceof Element) {
6
+ el.insertAdjacentElement('beforebegin', i);
7
+ } else if (i instanceof Text) {
8
+ // TextNode#toString() => "[object Text]" so we need to get it ourselves,
9
+ // Not sure why but the test in Node do not reflect this.
10
+ el.insertAdjacentText('beforebegin', i.textContent);
11
+ } else {
12
+ el.insertAdjacentText('beforebegin', i);
13
+ }
14
+ });
15
+ }
16
+
1
17
  function repalceejx(el, withItems) {
2
- if ( Array.isArray(withItems) ) {
3
- withItems.forEach((i) => {
4
- if (i instanceof Node) {
5
- el.insertAdjacentElement('beforebegin', i)
6
- } else {
7
- // el.insertAdjacentHTML()
8
- el.insertAdjacentText('beforebegin', i)
9
- }
10
- })
11
- el.remove();
12
- } else {
13
- el.replaceWith(withItems);
14
- }
18
+ if ( Array.isArray(withItems) ) {
19
+ insertBefore(el, withItems);
20
+ el.remove();
21
+ } else {
22
+ el.replaceWith(withItems);
23
+ }
15
24
  }
16
25
 
17
26
  export function append(items, to, escape, promises, promiseResults) {
@@ -23,12 +32,12 @@ export function append(items, to, escape, promises, promiseResults) {
23
32
  let holder = document.createElement( "div");
24
33
  to[method](holder);
25
34
  promises.push( items.then((resolvedItems) => {
26
- if(holder.parentElement) {
27
- repalceejx(holder, resolvedItems || promiseResults.flat())
35
+ if (holder.parentElement) {
36
+ repalceejx(holder, resolvedItems || promiseResults.flat());
28
37
  } else if (Array.isArray(resolvedItems)) {
29
- to.splice(to.indexOf(holder), 1, ...resolvedItems)
38
+ to.splice(to.indexOf(holder), 1, ...resolvedItems);
30
39
  } else {
31
- to.splice(to.indexOf(holder), 1, resolvedItems)
40
+ to.splice(to.indexOf(holder), 1, resolvedItems);
32
41
  }
33
42
  }));
34
43
  } else if (typeof items === 'string') {
data/lib/ejx/template.rb CHANGED
@@ -70,7 +70,7 @@ class EJX::Template
70
70
  @tree.last.children << subtemplate
71
71
  @stack.pop
72
72
  elsif pm.match(/function\s*\([^\)]*\)\s*\{\s*\Z/m) || pm.match(/=>\s*\{\s*\Z/m)
73
- @tree << EJX::Template::Subtemplate.new(pm.strip, [open_modifier, close_modifier].compact)
73
+ @tree << EJX::Template::Subtemplate.new(pm.strip, [open_modifier, close_modifier].compact, append: !pm.match?(/\A\s*(var|const|let)?\s*[^(]+\s*=/))
74
74
  @stack.pop
75
75
  else
76
76
  if open_modifier != :comment && !pre_js.empty? && @tree.last.children.last.is_a?(EJX::Template::JS)
@@ -1,19 +1,26 @@
1
1
  class EJX::Template::Subtemplate
2
2
 
3
- attr_reader :children
3
+ attr_reader :children, :append
4
4
 
5
- def initialize(opening, modifiers)
5
+ def initialize(opening, modifiers, append: true)
6
6
  @children = [opening]
7
7
  @modifiers = modifiers
8
+ @append = append
8
9
  end
9
10
 
10
11
  def to_js(indentation: 4, var_generator: nil, append: "__output")
11
12
  global_output_var = var_generator.next
12
13
  output_var = var_generator.next
13
14
 
14
- output = "#{' '*indentation}var #{global_output_var} = [];\n"
15
- output << "#{' '*indentation}__ejx_append("
16
- output << @children.first << "\n"
15
+ output = ''
16
+ if @append
17
+ output << "#{' '*indentation}var #{global_output_var} = [];\n"
18
+ output << "#{' '*indentation}__ejx_append("
19
+ output << @children.first << "\n"
20
+ else
21
+ output << "#{' '*indentation}#{@children.first}\n"
22
+ end
23
+
17
24
  output << "#{' '*(indentation+4)}var #{output_var} = [];\n"
18
25
 
19
26
  @children[1..-2].each do |child|
@@ -25,10 +32,14 @@ class EJX::Template::Subtemplate
25
32
  end
26
33
  end
27
34
 
28
- output << ' '*(indentation+4) << "#{global_output_var}.push(#{output_var});\n";
35
+ output << ' '*(indentation+4) << "#{global_output_var}.push(#{output_var});\n" if @append
29
36
  output << ' '*(indentation+4) << "return #{output_var};\n";
30
37
  output << ' '*indentation << @children.last.strip.delete_suffix(';')
31
- output << ", #{append}, true, __promises, #{global_output_var});\n"
38
+ output << if @append
39
+ ", #{append}, true, __promises, #{global_output_var});\n"
40
+ else
41
+ ";\n"
42
+ end
32
43
 
33
44
  output
34
45
  end
data/lib/ejx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module EJX
2
- VERSION = '1.0'
2
+ VERSION = '1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ejx
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2021-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement