zenml 1.3.0 → 1.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc0c51d446a26f7b640f5a4ab3c4054d131ab89f98ab7c0effca28387e06b9b9
4
- data.tar.gz: 43860c32ec5abf88af046191eeb57941ebc67cfde701229b459dfb2c9439f525
3
+ metadata.gz: 51365e366adfa0733bc6fd6ef3a608bb6303ed379aa1d4b71794ce279818ae89
4
+ data.tar.gz: e8c724e3e2e257eacdebf8e685f67e4610bf74c55a8f536bc9a0dad7a4cbd776
5
5
  SHA512:
6
- metadata.gz: baf2791fe4d95b718a2251152d8edb917e92c3d0da35ed9578ae1b4ac8fb2c48964223819eb9e06bd6619a25ee1e4bf84c4b10c81cf955f4a7b877a3a0db727d
7
- data.tar.gz: 0e8b566980d4870679e70426c5da2114abb3927c9c59f077f0e100b5c6685fab507bc141708744fb1d37f5294eb401900bf5019fa76a39e6d5e4e24a84ff5986
6
+ metadata.gz: 84b1ffa29a37dde0b4cdc121d876b80c8f7c9cf9a6a84201b37fe5b0ce67a22cc9e2f390c06b657be8814cc60bdcf90dd1a69dad225a944190a0de43f563f948
7
+ data.tar.gz: 3253f779d41e3810de4a9fef4c8daae49a4025ed6ee8ad0dff56f635d35a20a4903c5594c5d958d68f22d776df90dc06f8a24cca0767a00759dbab379721a9e9
data/source/zenml.rb CHANGED
@@ -6,7 +6,7 @@ require 'zenml/utility'
6
6
 
7
7
  module Zenithal
8
8
 
9
- VERSION = "1.3.0"
9
+ VERSION = "1.4.0"
10
10
 
11
11
  require 'zenml/error'
12
12
  require 'zenml/reader'
@@ -10,18 +10,28 @@ class ZenithalConverter
10
10
 
11
11
  SINGLETON_NAMES = ["br", "img", "hr", "meta", "input", "embed", "area", "base", "link"]
12
12
 
13
+ attr_reader :document
13
14
  attr_reader :configs
15
+ attr_reader :variables
14
16
 
15
17
  def initialize(document, type = :node)
16
18
  @document = document
17
19
  @type = type
18
20
  @configs = {}
21
+ @variables = {}
19
22
  @templates = {}
20
23
  @functions = {}
21
24
  @default_element_template = lambda{|_| empty_nodes}
22
25
  @default_text_template = lambda{|_| empty_nodes}
23
26
  end
24
27
 
28
+ # Changes the document to be converted.
29
+ # Note that this method initialises the configuration hash, but not the variable hash.
30
+ def update(document)
31
+ @document = document
32
+ @configs = {}
33
+ end
34
+
25
35
  def convert(initial_scope = "")
26
36
  document = nil
27
37
  if @type == :text
@@ -438,6 +438,11 @@ class ZenithalParser < Parser
438
438
  @plugins = {}
439
439
  end
440
440
 
441
+ def update(source)
442
+ super(source)
443
+ @version = nil
444
+ end
445
+
441
446
  # Registers a macro.
442
447
  # To the argument block will be passed two arguments: the first is a hash of the attributes, the second is a list of the children nodes.
443
448
  def register_macro(name, &block)
@@ -5,6 +5,8 @@ class Parser
5
5
 
6
6
  ERROR_TAG = Object.new
7
7
 
8
+ attr_reader :source
9
+
8
10
  def initialize(source)
9
11
  case source
10
12
  when StringReader
@@ -17,6 +19,18 @@ class Parser
17
19
  @inside_run = false
18
20
  end
19
21
 
22
+ def update(source)
23
+ case source
24
+ when StringReader
25
+ @source = source
26
+ when File
27
+ @source = StringReader.new(source.read)
28
+ else
29
+ @source = StringReader.new(source.to_s)
30
+ end
31
+ @inside_run = false
32
+ end
33
+
20
34
  def run
21
35
  value = nil
22
36
  message = catch(ERROR_TAG) do
@@ -5,6 +5,72 @@ require 'rexml/document'
5
5
  include REXML
6
6
 
7
7
 
8
+ class Tag
9
+
10
+ attr_accessor :name
11
+ attr_accessor :content
12
+
13
+ def initialize(name = nil, clazz = nil, close = true)
14
+ @name = name
15
+ @attributes = (clazz) ? {"class" => clazz} : {}
16
+ @content = ""
17
+ @close = close
18
+ end
19
+
20
+ def [](key)
21
+ return @attributes[key]
22
+ end
23
+
24
+ def []=(key, value)
25
+ @attributes[key] = value
26
+ end
27
+
28
+ def class
29
+ return @attributes["class"]
30
+ end
31
+
32
+ def class=(clazz)
33
+ @attributes["class"] = clazz
34
+ end
35
+
36
+ def <<(content)
37
+ @content << content
38
+ end
39
+
40
+ def to_s
41
+ result = ""
42
+ if @name
43
+ result << "<"
44
+ result << @name
45
+ @attributes.each do |key, value|
46
+ result << " #{key}=\"#{value}\""
47
+ end
48
+ result << ">"
49
+ result << @content
50
+ if @close
51
+ result << "</"
52
+ result << @name
53
+ result << ">"
54
+ end
55
+ else
56
+ result << @content
57
+ end
58
+ return result
59
+ end
60
+
61
+ def to_str
62
+ return self.to_s
63
+ end
64
+
65
+ def self.build(name = nil, clazz = nil, close = true, &block)
66
+ tag = Tag.new(name, clazz, close)
67
+ block.call(tag)
68
+ return tag
69
+ end
70
+
71
+ end
72
+
73
+
8
74
  class Element
9
75
 
10
76
  alias old_get_index []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziphil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-07 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  This gem serves a tool for parsing a document written in ZenML, an alternative new syntax for XML, to an XML node tree.