foreman_remote_execution 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +11 -9
  3. data/.rubocop_todo.yml +146 -116
  4. data/app/controllers/api/v2/job_invocations_controller.rb +6 -1
  5. data/app/controllers/api/v2/job_templates_controller.rb +0 -1
  6. data/app/controllers/job_invocations_controller.rb +6 -1
  7. data/app/lib/actions/remote_execution/run_host_job.rb +1 -1
  8. data/app/models/concerns/foreman_remote_execution/errors_flattener.rb +3 -0
  9. data/app/models/concerns/foreman_remote_execution/host_extensions.rb +1 -1
  10. data/app/models/concerns/foreman_remote_execution/subnet_extensions.rb +1 -1
  11. data/app/models/foreign_input_set.rb +1 -1
  12. data/app/models/job_invocation.rb +1 -1
  13. data/app/models/job_invocation_composer.rb +2 -2
  14. data/app/models/job_invocation_task_group.rb +1 -1
  15. data/app/models/job_template.rb +3 -3
  16. data/app/models/job_template_effective_user.rb +1 -1
  17. data/app/models/remote_execution_feature.rb +1 -1
  18. data/app/models/target_remote_execution_proxy.rb +1 -1
  19. data/app/models/targeting.rb +2 -2
  20. data/app/models/targeting_host.rb +1 -1
  21. data/app/models/template_input.rb +1 -1
  22. data/app/models/template_invocation.rb +1 -1
  23. data/app/models/template_invocation_input_value.rb +1 -1
  24. data/db/migrate/20150612121541_add_job_template_to_template.rb +1 -1
  25. data/db/migrate/20150616080015_create_template_input.rb +1 -1
  26. data/db/migrate/20150708133241_add_targeting.rb +1 -1
  27. data/db/migrate/20150708133242_add_invocation.rb +1 -1
  28. data/db/migrate/20150708133305_add_template_invocation.rb +1 -1
  29. data/db/migrate/20150812110800_add_resolved_at_to_targeting.rb +1 -1
  30. data/db/migrate/20150812145900_add_last_task_id_to_job_invocation.rb +1 -1
  31. data/db/migrate/20150826191632_create_target_remote_execution_proxies.rb +1 -1
  32. data/db/migrate/20150827144500_change_targeting_search_query_type.rb +1 -1
  33. data/db/migrate/20150827152730_add_options_to_template_input.rb +1 -1
  34. data/db/migrate/20150903192731_add_execution_to_interface.rb +2 -2
  35. data/db/migrate/20150923125825_add_job_invocation_task_group.rb +1 -1
  36. data/db/migrate/20151013135415_add_pub_key_to_smart_proxy.rb +1 -1
  37. data/db/migrate/20151022105508_rename_last_task_id_column.rb +1 -1
  38. data/db/migrate/20151116105412_add_triggering_to_job_invocation.rb +1 -1
  39. data/db/migrate/20151120171100_add_effective_user_to_template_invocation.rb +1 -1
  40. data/db/migrate/20151124162300_create_job_template_effective_users.rb +1 -1
  41. data/db/migrate/20151203100824_add_description_to_job_invocation.rb +1 -1
  42. data/db/migrate/20151215114631_add_host_id_to_template_invocation.rb +2 -2
  43. data/db/migrate/20151217092555_migrate_to_task_groups.rb +2 -2
  44. data/db/migrate/20160108134600_create_template_input_sets.rb +1 -1
  45. data/db/migrate/20160108141144_make_job_name_default_to_something.rb +1 -1
  46. data/db/migrate/20160111113032_upcase_ssh_feature.rb +2 -2
  47. data/db/migrate/20160113161916_add_run_host_job_task_id_to_template_invocation.rb +1 -1
  48. data/db/migrate/20160113162007_expand_all_template_invocations.rb +3 -3
  49. data/db/migrate/20160114120200_rename_job_categories.rb +1 -1
  50. data/db/migrate/20160114125628_rename_job_name_to_job_category.rb +1 -1
  51. data/db/migrate/20160118124600_create_remote_execution_features.rb +1 -1
  52. data/db/migrate/20160125155108_make_job_template_name_unique.rb +1 -1
  53. data/db/migrate/20160127134031_add_advanced_to_template_input.rb +1 -1
  54. data/db/migrate/20160127162711_reword_puppet_template_description.rb +1 -1
  55. data/db/migrate/20160203104056_add_concurrency_options_to_job_invocation.rb +1 -1
  56. data/db/migrate/20160926225841_update_template_input_value.rb +1 -1
  57. data/db/migrate/20170110145641_add_host_action_button_to_remote_execution_feature.rb +1 -1
  58. data/db/migrate/20170613101039_add_timeout_to_job_templates_and_job_invocations.rb +1 -1
  59. data/db/migrate/20180110104432_rename_template_invocation_permission.rb +25 -0
  60. data/db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb +14 -0
  61. data/db/seeds.d/90-bookmarks.rb +1 -1
  62. data/foreman_remote_execution.gemspec +2 -1
  63. data/lib/foreman_remote_execution/engine.rb +3 -3
  64. data/lib/foreman_remote_execution/version.rb +1 -1
  65. data/test/benchmark/run_hosts_job_benchmark.rb +10 -10
  66. data/test/benchmark/targeting_benchmark.rb +6 -6
  67. data/test/factories/foreman_remote_execution_factories.rb +14 -14
  68. data/test/functional/api/v2/foreign_input_sets_controller_test.rb +10 -15
  69. data/test/functional/api/v2/job_invocations_controller_test.rb +19 -8
  70. data/test/functional/api/v2/job_templates_controller_test.rb +12 -16
  71. data/test/functional/api/v2/remote_execution_features_controller_test.rb +3 -4
  72. data/test/functional/api/v2/template_inputs_controller_test.rb +8 -13
  73. data/test/test_plugin_helper.rb +4 -4
  74. data/test/unit/actions/run_hosts_job_test.rb +3 -3
  75. data/test/unit/concerns/exportable_test.rb +1 -1
  76. data/test/unit/concerns/foreman_tasks_cleaner_extensions_test.rb +2 -2
  77. data/test/unit/concerns/host_extensions_test.rb +20 -20
  78. data/test/unit/concerns/nic_extensions_test.rb +1 -1
  79. data/test/unit/input_template_renderer_test.rb +86 -86
  80. data/test/unit/job_invocation_composer_test.rb +17 -16
  81. data/test/unit/job_invocation_test.rb +10 -10
  82. data/test/unit/job_template_effective_user_test.rb +2 -2
  83. data/test/unit/job_template_importer_test.rb +3 -3
  84. data/test/unit/job_template_test.rb +15 -15
  85. data/test/unit/remote_execution_feature_test.rb +3 -3
  86. data/test/unit/remote_execution_provider_test.rb +15 -15
  87. data/test/unit/targeting_test.rb +3 -3
  88. data/test/unit/template_input_test.rb +1 -1
  89. data/test/unit/template_invocation_input_value_test.rb +17 -17
  90. metadata +19 -77
  91. data/doc/.gitignore +0 -7
  92. data/doc/Gemfile +0 -7
  93. data/doc/Rakefile +0 -41
  94. data/doc/_config.yml +0 -33
  95. data/doc/plugins/alert_block.rb +0 -27
  96. data/doc/plugins/div_tag.rb +0 -24
  97. data/doc/plugins/graphviz.rb +0 -121
  98. data/doc/plugins/plantuml.rb +0 -84
  99. data/doc/plugins/play.rb +0 -13
  100. data/doc/plugins/tags.rb +0 -137
  101. data/doc/plugins/toc.rb +0 -19
  102. data/doc/source/.nojekyll +0 -0
  103. data/doc/source/404.md +0 -6
  104. data/doc/source/_includes/footer.html +0 -21
  105. data/doc/source/_includes/header.html +0 -59
  106. data/doc/source/_includes/tocify.html +0 -6
  107. data/doc/source/_layouts/default.html +0 -9
  108. data/doc/source/_layouts/page.html +0 -25
  109. data/doc/source/atom.xml +0 -32
  110. data/doc/source/design/index.md +0 -1322
  111. data/doc/source/design/wireframes.pdf +0 -0
  112. data/doc/source/index.md +0 -18
  113. data/doc/source/static/css/bootstrap-responsive.min.css +0 -9
  114. data/doc/source/static/css/bootstrap.min.css +0 -866
  115. data/doc/source/static/css/jquery.tocify.css +0 -128
  116. data/doc/source/static/css/style.css +0 -285
  117. data/doc/source/static/css/syntax.css +0 -60
  118. data/doc/source/static/images/foreman.png +0 -0
  119. data/doc/source/static/images/glyphicons-halflings-white.png +0 -0
  120. data/doc/source/static/images/glyphicons-halflings.png +0 -0
  121. data/doc/source/static/js/bootstrap.min.js +0 -7
  122. data/doc/source/static/js/jquery-ui-1.9.2.custom.min.js +0 -6
  123. data/doc/source/static/js/jquery.js +0 -2
  124. data/doc/source/static/js/jquery.tocify.min.js +0 -3
  125. data/doc/source/static/js/scroll.js +0 -24
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_remote_execution
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Remote Execution team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.9.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_bot_rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.8.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -101,43 +115,6 @@ email:
101
115
  executables: []
102
116
  extensions: []
103
117
  extra_rdoc_files:
104
- - doc/.bin/.gitkeep
105
- - doc/.gitignore
106
- - doc/Gemfile
107
- - doc/Gemfile.lock
108
- - doc/Rakefile
109
- - doc/_config.yml
110
- - doc/plugins/alert_block.rb
111
- - doc/plugins/div_tag.rb
112
- - doc/plugins/graphviz.rb
113
- - doc/plugins/plantuml.rb
114
- - doc/plugins/play.rb
115
- - doc/plugins/tags.rb
116
- - doc/plugins/toc.rb
117
- - doc/source/.nojekyll
118
- - doc/source/404.md
119
- - doc/source/_includes/footer.html
120
- - doc/source/_includes/header.html
121
- - doc/source/_includes/tocify.html
122
- - doc/source/_layouts/default.html
123
- - doc/source/_layouts/page.html
124
- - doc/source/atom.xml
125
- - doc/source/design/index.md
126
- - doc/source/design/wireframes.pdf
127
- - doc/source/index.md
128
- - doc/source/static/css/bootstrap-responsive.min.css
129
- - doc/source/static/css/bootstrap.min.css
130
- - doc/source/static/css/jquery.tocify.css
131
- - doc/source/static/css/style.css
132
- - doc/source/static/css/syntax.css
133
- - doc/source/static/images/foreman.png
134
- - doc/source/static/images/glyphicons-halflings-white.png
135
- - doc/source/static/images/glyphicons-halflings.png
136
- - doc/source/static/js/bootstrap.min.js
137
- - doc/source/static/js/jquery-ui-1.9.2.custom.min.js
138
- - doc/source/static/js/jquery.js
139
- - doc/source/static/js/jquery.tocify.min.js
140
- - doc/source/static/js/scroll.js
141
118
  - README.md
142
119
  - LICENSE
143
120
  files:
@@ -315,46 +292,11 @@ files:
315
292
  - db/migrate/20160926225841_update_template_input_value.rb
316
293
  - db/migrate/20170110145641_add_host_action_button_to_remote_execution_feature.rb
317
294
  - db/migrate/20170613101039_add_timeout_to_job_templates_and_job_invocations.rb
295
+ - db/migrate/20180110104432_rename_template_invocation_permission.rb
296
+ - db/migrate/20180112125015_fix_taxable_taxonomies_job_template.rb
318
297
  - db/seeds.d/60-ssh_proxy_feature.rb
319
298
  - db/seeds.d/70-job_templates.rb
320
299
  - db/seeds.d/90-bookmarks.rb
321
- - doc/.bin/.gitkeep
322
- - doc/.gitignore
323
- - doc/Gemfile
324
- - doc/Gemfile.lock
325
- - doc/Rakefile
326
- - doc/_config.yml
327
- - doc/plugins/alert_block.rb
328
- - doc/plugins/div_tag.rb
329
- - doc/plugins/graphviz.rb
330
- - doc/plugins/plantuml.rb
331
- - doc/plugins/play.rb
332
- - doc/plugins/tags.rb
333
- - doc/plugins/toc.rb
334
- - doc/source/.nojekyll
335
- - doc/source/404.md
336
- - doc/source/_includes/footer.html
337
- - doc/source/_includes/header.html
338
- - doc/source/_includes/tocify.html
339
- - doc/source/_layouts/default.html
340
- - doc/source/_layouts/page.html
341
- - doc/source/atom.xml
342
- - doc/source/design/index.md
343
- - doc/source/design/wireframes.pdf
344
- - doc/source/index.md
345
- - doc/source/static/css/bootstrap-responsive.min.css
346
- - doc/source/static/css/bootstrap.min.css
347
- - doc/source/static/css/jquery.tocify.css
348
- - doc/source/static/css/style.css
349
- - doc/source/static/css/syntax.css
350
- - doc/source/static/images/foreman.png
351
- - doc/source/static/images/glyphicons-halflings-white.png
352
- - doc/source/static/images/glyphicons-halflings.png
353
- - doc/source/static/js/bootstrap.min.js
354
- - doc/source/static/js/jquery-ui-1.9.2.custom.min.js
355
- - doc/source/static/js/jquery.js
356
- - doc/source/static/js/jquery.tocify.min.js
357
- - doc/source/static/js/scroll.js
358
300
  - foreman_remote_execution.gemspec
359
301
  - lib/foreman_remote_execution.rb
360
302
  - lib/foreman_remote_execution/engine.rb
@@ -431,7 +373,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
431
373
  version: '0'
432
374
  requirements: []
433
375
  rubyforge_project:
434
- rubygems_version: 2.6.12
376
+ rubygems_version: 2.7.3
435
377
  signing_key:
436
378
  specification_version: 4
437
379
  summary: A plugin bringing remote execution to the Foreman, completing the config
@@ -1,7 +0,0 @@
1
- .idea
2
- .sass-cache
3
- .bin
4
- .ruby-version
5
- public
6
- resources
7
- tmp
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'jekyll'
4
- gem 'pry'
5
- gem 'rake'
6
- gem 'ruby-nuggets' # require by tags plugin
7
- gem 'therubyracer'
@@ -1,41 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- root = File.dirname __FILE__
5
-
6
- task :default => :publish
7
-
8
- def system(cmd)
9
- puts ">> #{cmd}"
10
- super cmd
11
- end
12
-
13
- task :plantuml_install do
14
- unless File.exist?('.bin/plantuml.jar')
15
- sh 'wget https://downloads.sourceforge.net/project/plantuml/plantuml.jar -O .bin/plantuml.jar'
16
- end
17
- end
18
-
19
- task :fetch do
20
- unless File.exist?('public/.git')
21
- FileUtils.rm_rf('public')
22
- sh 'git clone git@github.com:theforeman/foreman_remote_execution.git public'
23
- end
24
- Dir.chdir('public') do
25
- sh 'git fetch --all'
26
- sh 'git checkout gh-pages'
27
- sh 'git reset --hard origin/gh-pages'
28
- end
29
- end
30
-
31
- task :build => :plantuml_install do
32
- sh 'jekyll build'
33
- end
34
-
35
- task :publish => [:fetch, :build] do
36
- Dir.chdir('public') do
37
- sh 'git add -A .'
38
- sh 'git commit -m Update'
39
- sh 'git push'
40
- end
41
- end
@@ -1,33 +0,0 @@
1
- ---
2
- name: Formean Remote Execution
3
- title: Foreman Remote Execution
4
- url: http://theforeman.github.io
5
- baseurl: /foreman_remote_execution/
6
- markdown: redcarpet
7
- highlighter: pygments
8
-
9
- source: ./source
10
- destination: ./public
11
- plugins: ./plugins
12
- include:
13
- - .nojekyll
14
-
15
- tag_page_layout: tag_page
16
- tag_page_dir: tag
17
-
18
- permalink: /blog/:year/:month/:day/:title/
19
-
20
- sass:
21
- sass_dir: _sass
22
-
23
- redcarpet:
24
- extensions:
25
- - with_toc_data
26
- - html_toc
27
- - strikethrough
28
-
29
- plantuml:
30
- plantuml_jar: .bin/plantuml.jar # path to plantuml jar
31
- tmp_folder: tmp # tmp folder to put generated image files
32
- background_color: transparent # [optional] UML image background color
33
- # dot_exe: /usr/local/bin/dot # [optional] path to Graphviz dot execution
@@ -1,27 +0,0 @@
1
- require_relative 'div_tag'
2
-
3
- module Jekyll
4
- class AlertBlock < DivTag
5
- def initialize(tag_name, markup, tokens)
6
- @alert_type = tag_name.split('_').first
7
- super tag_name, markup + ' alert alert-' + @alert_type, tokens
8
- end
9
-
10
- def tag
11
- 'div'
12
- end
13
-
14
- HEADER = { 'info' => 'Note',
15
- 'warning' => 'Warning',
16
- 'danger' => 'Danger' }
17
-
18
- def render_content(context, content)
19
- super context, "**#{HEADER[@alert_type]}** \n" + content
20
- end
21
- end
22
- end
23
-
24
- Liquid::Template.register_tag('info_block', Jekyll::AlertBlock)
25
- Liquid::Template.register_tag('warning_block', Jekyll::AlertBlock)
26
- Liquid::Template.register_tag('danger_block', Jekyll::AlertBlock)
27
- # Liquid::Template.register_tag('success_block', Jekyll::AlertBlock)
@@ -1,24 +0,0 @@
1
- module Jekyll
2
- class DivTag < Liquid::Block
3
- def render(context)
4
- content = super
5
-
6
- <<-HTML.gsub(/^ +\|/, '')
7
- |<#{tag} class="#{@markup}">
8
- | #{render_content context, content}
9
- |</#{tag}>
10
- HTML
11
- end
12
-
13
- def tag
14
- @tag_name.split('_').first
15
- end
16
-
17
- def render_content(context, content)
18
- context.registers[:site].converters.find { |c| c.is_a? Jekyll::Converters::Markdown }.convert(content)
19
- end
20
- end
21
- end
22
-
23
- Liquid::Template.register_tag('div_tag', Jekyll::DivTag)
24
- Liquid::Template.register_tag('span_tag', Jekyll::DivTag)
@@ -1,121 +0,0 @@
1
- # taken from https://raw.githubusercontent.com/kui/octopress-graphviz/master/graphviz_block.rb
2
-
3
- require 'open3'
4
-
5
- module Jekyll
6
- class GraphvizBlock < Liquid::Block
7
-
8
- DIV_CLASS_ATTR = 'graphviz-wrapper'
9
- DEFAULT_GRAPH_NAME = 'Graphviz'
10
- DOT_OPTS = '-Tsvg'
11
- DOT_EXEC = 'dot'
12
- DOT_EXTS = (ENV['PATHEXT'] || '.exe;.bat;.com').split(';')
13
- DOT_EXTS.unshift ''
14
- DOT_PATH = ENV['PATH'].split(File::PATH_SEPARATOR)
15
- .map { |a| File.join a, DOT_EXEC }
16
- .map { |a| DOT_EXTS.map { |ex| a+ex } }.flatten
17
- .find { |c| File.executable_real? c }
18
- raise "not found a executable file: #{DOT_EXEC}" if DOT_PATH.nil?
19
- DOT_CMD = "#{DOT_PATH} #{DOT_OPTS}"
20
-
21
- def initialize(tag_name, markup, tokens)
22
- super
23
- @tag_name = tag_name
24
-
25
- @title = markup or ''
26
- @title.strip!
27
-
28
- @src = ''
29
- end
30
-
31
- def render(context)
32
- code = super
33
- title = if @title.empty? then
34
- DEFAULT_GRAPH_NAME
35
- else
36
- @title
37
- end
38
-
39
- case @tag_name
40
- when 'graphviz' then
41
- render_graphviz code
42
- when 'graph' then
43
- render_graph 'graph', title, code
44
- when 'digraph' then
45
- render_graph 'digraph', title, code
46
- else
47
- raise "unknown liquid tag name: #{@tag_name}"
48
- end
49
- end
50
-
51
- def render_graphviz(code)
52
- @src = code
53
- svg = generate_svg code
54
- filter_for_inline_svg svg
55
- end
56
-
57
- def filter_for_inline_svg(code)
58
- code = remove_declarations code
59
- code = remove_xmlns_attrs code
60
- code = add_desc_attrs code
61
- code = insert_desc_elements code
62
- code = wrap_with_div code
63
- code = code.gsub /<polygon fill="white" stroke="none"/, '<polygon fill="transparent" stroke="none"'
64
- code
65
- end
66
-
67
- def generate_svg code
68
- Open3.popen3(DOT_CMD) do |stdin, stdout, stderr|
69
- stdout.binmode
70
- stdin.print code
71
- stdin.close
72
-
73
- err = stderr.read
74
- if not (err.nil? || err.strip.empty?)
75
- raise "Error from #{DOT_CMD}:\n#{err}"
76
- end
77
-
78
- svg = stdout.read
79
- svg.force_encoding 'UTF-8'
80
-
81
- return svg
82
- end
83
- end
84
-
85
- def remove_declarations(svg)
86
- svg.sub(/<!DOCTYPE .+?>/im, '').sub(/<\?xml .+?\?>/im, '')
87
- end
88
-
89
- def remove_xmlns_attrs(svg)
90
- svg.sub(%[xmlns="http://www.w3.org/2000/svg"], '')
91
- .sub(%[xmlns:xlink="http://www.w3.org/1999/xlink"], '')
92
- end
93
-
94
- def add_desc_attrs(svg)
95
- svg.sub!('<svg', %[<svg aria-label="#{CGI::escapeHTML @title}"])
96
- svg.sub!('<svg', %[<svg role="img"])
97
-
98
- return svg
99
- end
100
-
101
- def insert_desc_elements(svg)
102
- inserted_elements = %[<title>#{CGI::escapeHTML @title}</title>\n]
103
- inserted_elements << %[<desc>#{CGI::escapeHTML @src}</desc>\n]
104
- svg.sub!(/(<svg [^>]*>)/, "\\1\n#{inserted_elements}")
105
-
106
- return svg
107
- end
108
-
109
- def wrap_with_div(svg)
110
- %[<div class="#{DIV_CLASS_ATTR}">#{svg}</div>]
111
- end
112
-
113
- def render_graph(type, title, code)
114
- render_graphviz %[#{type} "#{title}" { #{code} }]
115
- end
116
- end
117
- end
118
-
119
- Liquid::Template.register_tag('graphviz', Jekyll::GraphvizBlock)
120
- Liquid::Template.register_tag('graph', Jekyll::GraphvizBlock)
121
- Liquid::Template.register_tag('digraph', Jekyll::GraphvizBlock)
@@ -1,84 +0,0 @@
1
- # Title: PlantUML Code Blocks for Jekyll
2
- # Author: YJ Park (yjpark@gmail.com)
3
- # https://github.com/yjpark/jekyll-plantuml
4
- # Description: Integrate PlantUML into Jekyll and Octopress.
5
- #
6
- # Syntax:
7
- # {% plantuml %}
8
- # plantuml code
9
- # {% endplantuml %}
10
- #
11
- require 'open3'
12
- require 'fileutils'
13
-
14
- module Jekyll
15
-
16
- class PlantUMLBlock < Liquid::Block
17
- attr_reader :config
18
-
19
- def render(context)
20
- site = context.registers[:site]
21
- self.config = site.config['plantuml']
22
-
23
- tmproot = File.expand_path(tmp_folder)
24
- folder = '/images/plantuml/'
25
- create_tmp_folder(tmproot, folder)
26
-
27
- code = @nodelist.join + background_color
28
- filename = Digest::MD5.hexdigest(code) + '.png'
29
- filepath = tmproot + folder + filename
30
- if !File.exist?(filepath)
31
- plantuml_jar = File.expand_path(plantuml_jar_path)
32
- cmd = 'java -Djava.awt.headless=true -jar ' + plantuml_jar + dot_cmd + ' -pipe > ' + filepath
33
- result, status = Open3.capture2e(cmd, :stdin_data=>code)
34
- Jekyll.logger.debug(filepath + " -->\t" + status.inspect() + "\t" + result)
35
- end
36
-
37
- site.static_files << Jekyll::StaticFile.new(site, tmproot, folder, filename)
38
-
39
- "<img src='#{site.baseurl}/#{folder}#{filename}>"
40
- end
41
-
42
- private
43
-
44
- def config=(cfg)
45
- @config = cfg || Jekyll.logger.abort_with("Missing 'plantuml' configurations.")
46
- end
47
-
48
- def background_color
49
- config['background_color'].nil? ? '' : ' skinparam backgroundColor ' + config['background_color']
50
- end
51
-
52
- def plantuml_jar_path
53
- config['plantuml_jar'] || Jekyll.logger.abort_with("Missing configuration 'plantuml.plantuml_jar'.")
54
- end
55
-
56
- def tmp_folder
57
- config['tmp_folder'] || Jekyll.logger.abort_with("Missing configuration 'plantuml.tmp_folder'.")
58
- end
59
-
60
- def dot_cmd
61
- @dot_cmd ||= begin
62
- dotpath = File.expand_path(config['dot_exe'] || '__NULL__')
63
- if File.exist?(dotpath)
64
- # Jekyll.logger.info("PlantUML: Use graphviz dot: " + dotpath)
65
- ' -graphvizdot ' + dotpath
66
- else
67
- # Jekyll.logger.info("PlantUML: Assume graphviz dot is in PATH.")
68
- ''
69
- end
70
- end
71
- end
72
-
73
- def create_tmp_folder(tmproot, folder)
74
- folderpath = tmproot + folder
75
- if !File.exist?(folderpath)
76
- FileUtils::mkdir_p folderpath
77
- Jekyll.logger.info('Create PlantUML image folder: ' + folderpath)
78
- end
79
- end
80
-
81
- end # PlantUMLBlock
82
- end
83
-
84
- Liquid::Template.register_tag('plantuml', Jekyll::PlantUMLBlock)