markdown-expander 0.3.0 → 0.4.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: 08884e0ba6130f82bde17019674c76462d0c02fc
4
- data.tar.gz: 5fe09c64e9f0962720abf743145a5f557fcb5e5b
3
+ metadata.gz: dec4cfc4d81d3e1fb1bd1c9d819fb1787725184e
4
+ data.tar.gz: 9fb3a69fc05ccc7f5fe004c9d23382f1e33aaa50
5
5
  SHA512:
6
- metadata.gz: 9f3f14364a5409cc72d537ae03226a93f9fb3d5331fb2ad00c3a57e9e0512332d8259f4c2f323a75bb5e36023bc275bc30dc5584a5f28bcdfa9cd2699d530a64
7
- data.tar.gz: 835a848e9853d38de2d80aa3d085dc4feee46b334fe35652b8c85bac537d3c8442cef73d46e81859ee2d4411c342a6ee3a83ded495cc2067c3797849c555ac95
6
+ metadata.gz: 286118a7ac49628c4c0915b34b6d8525e0f070d356934bd143c9dd491a84d866a86722cca97295b3a4ca371ccd9c8c52e6e0feeaf4844d849746699906e540ac
7
+ data.tar.gz: a3fb4536c86024b03051eb7c8c9c4a0f42d3be1628d572220849fe236c399a4e3a4402322da52f144d8f361eaffb1f18e2c8d90c04d40d10a11f63ac72e211a8
data/README.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # markdown-expander
2
2
 
3
- Adds some new syntax to markdown
3
+ A preprocessor for markdown that adds simple logic.
4
+
5
+ ## Why would you do this?????
6
+
7
+ This was written to be used on anmo.io, where users can create web pages with
8
+ markdown, but also need to have some simple templating language.
9
+
10
+ Because users are going to be inputting content, I can't use any templating
11
+ language that allows them to execute ruby code.
12
+
13
+ Liquid seemed far too complex and heavyweight for what I want and also didn't
14
+ work well when mixed with markdown.
4
15
 
5
16
  ## Installation
6
17
 
data/README.md.docu CHANGED
@@ -1,6 +1,17 @@
1
1
  # markdown-expander
2
2
 
3
- Adds some new syntax to markdown
3
+ A preprocessor for markdown that adds simple logic.
4
+
5
+ ## Why would you do this?????
6
+
7
+ This was written to be used on anmo.io, where users can create web pages with
8
+ markdown, but also need to have some simple templating language.
9
+
10
+ Because users are going to be inputting content, I can't use any templating
11
+ language that allows them to execute ruby code.
12
+
13
+ Liquid seemed far too complex and heavyweight for what I want and also didn't
14
+ work well when mixed with markdown.
4
15
 
5
16
  ## Installation
6
17
 
@@ -3,8 +3,9 @@ require "version"
3
3
  module MarkdownExpander
4
4
  class Expander
5
5
  LOOP_START_MATCH = /{{\s*([a-zA-Z_]*)\s+in\s+([a-zA-Z_.]*)\s*}}/
6
- LOOP_END_MATCH = /{{\s*end\s*}}/
6
+ END_MATCH = /{{\s*end\s*}}/
7
7
  EXPRESSION_MATCH = /{{\s*([a-zA-Z_.]+)\s*}}/
8
+ IF_START_MATCH = /{{\s*if\s*([a-zA-Z_.]*)\s*(==|!=)\s*"(.*)"}}/
8
9
 
9
10
  def initialize template
10
11
  @template = template
@@ -19,8 +20,12 @@ module MarkdownExpander
19
20
  new_node = Node.new(node, LoopStart.new($1, $2))
20
21
  node.children << new_node
21
22
  node = new_node
22
- elsif line =~ LOOP_END_MATCH
23
+ elsif line =~ END_MATCH
23
24
  node = node.parent
25
+ elsif line =~ IF_START_MATCH
26
+ new_node = Node.new(node, IfStart.new($1, $2, $3))
27
+ node.children << new_node
28
+ node = new_node
24
29
  else
25
30
  loop do
26
31
  if line =~ EXPRESSION_MATCH
@@ -54,6 +59,20 @@ module MarkdownExpander
54
59
  scope.each do |item|
55
60
  lines << evaluate_nodes(child, {name => item})
56
61
  end
62
+ elsif child.value.class == IfStart
63
+ parts = child.value.expression.split(".")
64
+ value = scope
65
+ parts.each do |part|
66
+ value = value[part.to_sym]
67
+ end
68
+ expression_satisfied =
69
+ (child.value.operator == "==" && value.to_s == child.value.value) ||
70
+ (child.value.operator == "!=" && value.to_s != child.value.value)
71
+ if expression_satisfied
72
+ scope.each do |item|
73
+ lines << evaluate_nodes(child, scope)
74
+ end
75
+ end
57
76
  else
58
77
  lines << child.value
59
78
  end
@@ -80,6 +99,17 @@ module MarkdownExpander
80
99
  end
81
100
  end
82
101
 
102
+ class IfStart
103
+ attr_accessor :expression
104
+ attr_accessor :operator
105
+ attr_accessor :value
106
+ def initialize expression, operator, value
107
+ @expression = expression
108
+ @operator = operator
109
+ @value = value
110
+ end
111
+ end
112
+
83
113
  class Expression
84
114
  def initialize value
85
115
  @value = value
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MarkdownExpander
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown-expander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Vos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler