liquidot 0.0.2 → 0.0.3

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ldot +42 -0
  3. data/bin/liquidot +1 -1
  4. data/lib/liquidot.rb +25 -4
  5. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92aeb8ddf70f17edc7954ba79158b9673f570e36ad82fd34e205c893824cda45
4
- data.tar.gz: 37c3b87261842e4afb2fd369a87dd95b1157ba426f74a2257ef41c7682485524
3
+ metadata.gz: 21fdd3d1ca1fbad0b7781534fe8536c2e6e1ed38bf816f41a38c1a79f8697527
4
+ data.tar.gz: 9cee589b35950dbd571da7ba5412b02783effa22f81e263824c675bdc238f1af
5
5
  SHA512:
6
- metadata.gz: 5b3244b157635ba5f1acc0357b8318df900abeead36a13ff7918f187b470119771fab24d12dc78219fed25e891ac13399efbde956e4c14635f35058f1d1cdee9
7
- data.tar.gz: 408296e9a0cbc124c503fede145e163dad111b73fbfcc1dcc5faa882e47fd74a099a07b89e603bd00cfe5cf3559001cd9689e11d172f2c800053faf9a89f9b2f
6
+ metadata.gz: 2103073adce9fffc87f474b3d681f901d1f7c9afdc28a4957ab88707d705f959fb35bf70fb6c1d24c08cebe0626032632def48d8e2715b2bad16b29d8ce1eae1
7
+ data.tar.gz: dcda0efb5cf8152407f2759fc6e77c3ba717daadd0c253dce8dabbfa0482f97067eb1688428736ae81cc07195fecabb579f098fae1a574bea22ed6bee897f88d
data/bin/ldot ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'liquidot'
4
+ require 'graphviz'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ optionparser = OptionParser.new do |opts|
9
+ opts.banner = "Usage: ldot [OPTIONS] infile"
10
+
11
+ opts.on('-f', '--format FORMAT', 'Output filetype') do |v|
12
+ options[:format] = v
13
+ end
14
+
15
+ opts.on('-o', '--output-filename OUTFILE', 'Output filename') do |v|
16
+ options[:outfile] = v
17
+ end
18
+
19
+ end
20
+ rest = optionparser.parse!
21
+
22
+ graphviz_args = {}
23
+
24
+ case
25
+ when (options[:format] and options[:outfile])
26
+ graphviz_args[options[:format]] = options[:outfile]
27
+ when options[:format]
28
+ graphviz_args[options[:format]] = nil
29
+ when options[:outfile]
30
+ graphviz_args[:output] = options[:outfile]
31
+ else
32
+ graphviz_args[:svg] = nil
33
+ end
34
+
35
+ if rest.empty?
36
+ puts optionparser
37
+ exit(-1)
38
+ end
39
+
40
+ rendered_graphviz = LiquiDot::Template.parse(rest.pop).render()
41
+
42
+ GraphViz.parse_string(rendered_graphviz).output(graphviz_args)
data/bin/liquidot CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'liquidot'
4
4
 
5
- puts LiquiDot::format(ARGF.read)
5
+ puts LiquiDot::Template.parse(ARGV[0]).render()
data/lib/liquidot.rb CHANGED
@@ -2,12 +2,33 @@ require 'liquid'
2
2
  require 'yaml'
3
3
 
4
4
  module LiquiDot
5
- def self.format(raw_liquid, args=nil)
6
- if raw_liquid =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
7
- raw_liquid = $POSTMATCH
5
+ class Template
6
+ def initialize(content, data={})
7
+ @content = content
8
+ @data = data
9
+ end
10
+
11
+ def self.parse(filename)
12
+ s = File.read(filename)
13
+ self.parse_string(s)
14
+ end
15
+
16
+ def self.parse_string(content)
17
+ data = {}
18
+ if content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
19
+ content = $POSTMATCH
8
20
  data = YAML.load($1)
9
21
  end
10
- template = Liquid::Template.parse(raw_liquid)
22
+ Template.new(content, data)
23
+ end
24
+
25
+ def render(newdata={})
26
+ template = Liquid::Template.parse(@content)
27
+ data = @data
28
+ if !data.empty?
29
+ data.merge!(newdata)
30
+ end
11
31
  template.render(data)
32
+ end
12
33
  end
13
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquidot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronni Elken Lindsgaard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-03 00:00:00.000000000 Z
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-graphviz
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -60,6 +74,7 @@ executables:
60
74
  extensions: []
61
75
  extra_rdoc_files: []
62
76
  files:
77
+ - bin/ldot
63
78
  - bin/liquidot
64
79
  - lib/liquidot.rb
65
80
  homepage: http://rubygems.org/gems/liquidot