liquidoc 0.9.5 → 0.10.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
  SHA256:
3
- metadata.gz: 12b5d860a86e2b0c934b1cfc196df2a4ff6c92261eeea9770259716874f4b27f
4
- data.tar.gz: 81e2e73815e12bccd7c4c09217ba1d86f6d8a96e4584842ebe2d2668958fe341
3
+ metadata.gz: 8f251c6530c83d406052a8adc81a10048a65be63f7041bb3a8d9e6031514f69a
4
+ data.tar.gz: 104ba3413ecc11bbee5afd5064ac818287a2a27164fb6943c65dbb41625359c3
5
5
  SHA512:
6
- metadata.gz: b2c552ee847fc84d2a45333f00923c8a1d5305fa3db8a4c262b2ebfec7da234222471e7e5a88e72edff1b9c88213a092d9fc2caa083a671f56a05f406ccd3d7c
7
- data.tar.gz: 60fa6c8196d38b609f5a59f8d922c89d25926d4122bb437e82b455a3c3ad2902b61bb6c9269e59acff97c425c6a11b02e0b7e97f2da1bc74409251098d43f2fd
6
+ metadata.gz: '09bacdea17f0eaa5e2f26db3705031801c05b3730d9ea82b37294351d1acc1a01110621ea301099d7f5b170e334c2aa3be5bace5d2e85f14c2819ffd12bdd5b2'
7
+ data.tar.gz: 33da833e1f3b747e87747edf4a731a04aea4bcc4da6ca48a5af8c6d7f4a25049c9ebaf5cbf89f51476e1c107e63ea08b2b5d60fa27fa956b48fa48ab3f14815f
@@ -10,6 +10,8 @@ require 'csv'
10
10
  require 'crack/xml'
11
11
  require 'fileutils'
12
12
  require 'jekyll'
13
+ require 'open3'
14
+ require 'highline'
13
15
 
14
16
  # ===
15
17
  # Table of Contents
@@ -53,6 +55,7 @@ require 'jekyll'
53
55
  @explicit = false
54
56
  @search_index = false
55
57
  @search_index_dry = ''
58
+ @safemode = true
56
59
 
57
60
  # Instantiate the main Logger object, which is always running
58
61
  @logger = Logger.new(STDOUT)
@@ -95,6 +98,20 @@ def config_build config_file, config_vars={}, parse=false
95
98
  raise "ConfigFileError"
96
99
  end
97
100
  cfg = BuildConfig.new(config) # convert the config file to a new object called 'cfg'
101
+ if @safemode
102
+ commands = ""
103
+ cfg.steps.each do |step|
104
+ if step['action'] == "execute"
105
+ commands = commands + "> " + step['command'] + "\n"
106
+ end
107
+ end
108
+ unless commands.to_s.strip.empty?
109
+ puts "\nWARNING: This routine will execute the following shell commands:\n\n#{commands}"
110
+ ui = HighLine.new
111
+ answer = ui.ask("\nDo you approve? (YES/no): ")
112
+ raise "CommandExecutionsNotAuthorized" unless answer.strip == "YES"
113
+ end
114
+ end
98
115
  iterate_build(cfg)
99
116
  end
100
117
 
@@ -144,6 +161,9 @@ def iterate_build cfg
144
161
  when "deploy"
145
162
  @logger.warn "Deploy actions are limited and experimental."
146
163
  jekyll_serve(build)
164
+ when "execute"
165
+ @logger.info "Executing shell command: #{step.command}"
166
+ execute_command(step)
147
167
  else
148
168
  @logger.warn "The action `#{type}` is not valid."
149
169
  end
@@ -213,6 +233,23 @@ def explainer_init out=nil
213
233
  end
214
234
  end
215
235
 
236
+ def generate_file content, target
237
+ base_path = File.dirname(target)
238
+ begin
239
+ FileUtils::mkdir_p(base_path) unless File.exists?(base_path)
240
+ File.open(target, 'w') { |file| file.write(content) } # saves file
241
+ rescue Exception => ex
242
+ @logger.error "Failed to save output.\n#{ex.class} #{ex.message}"
243
+ raise "FileNotBuilt"
244
+ end
245
+ if File.exists?(target)
246
+ @logger.info "File built: #{target}"
247
+ else
248
+ @logger.error "Hrmp! File not built."
249
+ raise "FileNotBuilt"
250
+ end
251
+ end
252
+
216
253
  # ===
217
254
  # Core classes
218
255
  # ===
@@ -280,6 +317,10 @@ class BuildConfigStep
280
317
  return @step['options']
281
318
  end
282
319
 
320
+ def command
321
+ return @step['command']
322
+ end
323
+
283
324
  def stage
284
325
  return @step['stage']
285
326
  end
@@ -345,6 +386,8 @@ class BuildConfigStep
345
386
  reqs = ["source,target"]
346
387
  when "render"
347
388
  reqs = ["builds"]
389
+ when "execute"
390
+ reqs = ["command"]
348
391
  end
349
392
  for req in reqs
350
393
  if (defined?(@step[req])).nil?
@@ -745,20 +788,7 @@ def liquify datasrc, template_file, output, variables=nil
745
788
  end
746
789
  unless output.downcase == "stdout"
747
790
  output_file = output
748
- base_path = File.dirname(output)
749
- begin
750
- FileUtils::mkdir_p(base_path) unless File.exists?(base_path)
751
- File.open(output_file, 'w') { |file| file.write(rendered) } # saves file
752
- rescue Exception => ex
753
- @logger.error "Failed to save output.\n#{ex.class} #{ex.message}"
754
- raise "FileNotBuilt"
755
- end
756
- if File.exists?(output_file)
757
- @logger.info "File built: #{output_file}"
758
- else
759
- @logger.error "Hrmp! File not built."
760
- raise "FileNotBuilt"
761
- end
791
+ generate_file(rendered, output_file)
762
792
  else # if stdout
763
793
  puts "========\nOUTPUT: Rendered with template #{template_file}:\n\n#{rendered}\n"
764
794
  end
@@ -924,9 +954,6 @@ def asciidocify doc, build
924
954
  if build.backend == "pdf"
925
955
  @logger.info "Generating PDF. This can take some time..."
926
956
  end
927
-
928
-
929
-
930
957
  Asciidoctor.convert_file(
931
958
  doc.index,
932
959
  to_file: to_file,
@@ -1018,6 +1045,38 @@ def algolia_index_cmd build, apikey=nil, args
1018
1045
  end
1019
1046
  end
1020
1047
 
1048
+ # ===
1049
+ # Execute
1050
+ # ===
1051
+
1052
+ def execute_command cmd
1053
+ stdout, stderr, status = Open3.capture3(cmd.command)
1054
+ failed = true if status.to_s.include?("exit 1")
1055
+ unless cmd.options
1056
+ puts stdout
1057
+ puts stderr if failed
1058
+ else
1059
+ if failed && cmd.options['error']
1060
+ @logger.warn cmd.options['error']['message'] if cmd.options['error']['message']
1061
+ if cmd.options['error']['response'] == "exit"
1062
+ @logger.error "Command failure: #{stderr}"
1063
+ raise "CommandExecutionException"
1064
+ end
1065
+ end
1066
+ if cmd.options['outfile']
1067
+ contents = stdout
1068
+ if cmd.options['outfile']
1069
+ contents = "#{cmd.options['outfile']['prepend']}\n#{stdout}" if cmd.options['outfile']['prepend']
1070
+ contents = "#{stdout}/n#{cmd.options['outfile']['append']}" if cmd.options['outfile']['append']
1071
+ generate_file(contents, cmd.options['outfile']['path'])
1072
+ end
1073
+ if cmd.options['stdout']
1074
+ puts stdout
1075
+ end
1076
+ end
1077
+ end
1078
+ end
1079
+
1021
1080
  # ===
1022
1081
  # Text manipulation Classes, Modules, procs, etc
1023
1082
  # ===
@@ -1224,6 +1283,10 @@ command_parser = OptionParser.new do|opts|
1224
1283
  @parseconfig = true
1225
1284
  end
1226
1285
 
1286
+ opts.on("--unsafe", "Enable shell command executions without interactive check.") do
1287
+ @safemode = false
1288
+ end
1289
+
1227
1290
  opts.on("-h", "--help", "Returns help.") do
1228
1291
  puts opts
1229
1292
  exit
@@ -1,3 +1,3 @@
1
1
  module Liquidoc
2
- VERSION = "0.9.5"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquidoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dominick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-15 00:00:00.000000000 Z
11
+ date: 2019-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,132 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: asciidoctor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: liquid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: asciidoctor-pdf
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.0.alpha.16
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.5.0.alpha.16
97
+ - !ruby/object:Gem::Dependency
98
+ name: logger
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: crack
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.4'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: jekyll
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: jekyll-asciidoc
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: highline
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '2.0'
41
167
  description: LiquiDoc conveniently harnesses the power of Liquid templates, flat-file
42
168
  data formats such as YAML, JSON, XML, and CSV, as well as AsciiDoc markup and powerful
43
169
  Asciidoctor output capabilities -- all in a single command-line tool.
@@ -49,7 +175,6 @@ extensions: []
49
175
  extra_rdoc_files: []
50
176
  files:
51
177
  - bin/liquidoc
52
- - lib/asciidoctor/xref-stripper-preprocessor.rb
53
178
  - lib/liquidoc.rb
54
179
  - lib/liquidoc/version.rb
55
180
  homepage: https://github.com/scalingdata/liquidoc
@@ -65,12 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
190
  requirements:
66
191
  - - ">="
67
192
  - !ruby/object:Gem::Version
68
- version: '0'
193
+ version: 2.3.0
69
194
  required_rubygems_version: !ruby/object:Gem::Requirement
70
195
  requirements:
71
196
  - - ">="
72
197
  - !ruby/object:Gem::Version
73
- version: '0'
198
+ version: 2.7.0
74
199
  requirements: []
75
200
  rubyforge_project:
76
201
  rubygems_version: 2.7.6
@@ -1,13 +0,0 @@
1
- require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
2
-
3
- include Asciidoctor
4
-
5
- Extensions.register {
6
- preprocessor {
7
- process {|document, reader|
8
- Reader.new reader.readlines.map {|l|
9
- (l.empty? || (l.start_with? '=')) ? l : %(#{l} +)
10
- }
11
- }
12
- }
13
- }