Module: Jekyll::Diagrams::Utils
- Defined in:
- lib/jekyll-diagrams/utils.rb
Class Method Summary collapse
- .config_for(context, name) ⇒ Object
-
.configuration(context) ⇒ Object
Return configuration of Jekyll Diagrams.
-
.error_mode(context) ⇒ Object
Return error mode in user configuration.
- .handle_error(context, error) ⇒ Object
- .normalized_attrs(attrs, prefix:, sep: '=') ⇒ Object
- .run_jar(jar) ⇒ Object
- .vendor_path(file = '') ⇒ Object
- .wrap_class(content, class_names) ⇒ Object
Class Method Details
.config_for(context, name) ⇒ Object
20 21 22 |
# File 'lib/jekyll-diagrams/utils.rb', line 20 def config_for(context, name) configuration(context).dig(Diagrams.config_name, name) || {} end |
.configuration(context) ⇒ Object
Return configuration of Jekyll Diagrams
12 13 14 15 16 17 |
# File 'lib/jekyll-diagrams/utils.rb', line 12 def configuration(context) site_config = context.registers[:site].config page_config = context.registers[:page] site_config.merge(page_config) end |
.error_mode(context) ⇒ Object
Return error mode in user configuration
27 28 29 30 31 32 33 34 35 |
# File 'lib/jekyll-diagrams/utils.rb', line 27 def error_mode(context) key = 'error_mode' config = configuration(context) liquid_mode = config.dig('liquid', key) custom_mode = config.dig(Diagrams.config_name, key) (custom_mode || liquid_mode || Diagrams.default_error_mode).to_sym end |
.handle_error(context, error) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll-diagrams/utils.rb', line 37 def handle_error(context, error) topic = Diagrams.logger_topic mode = error_mode(context) case mode when :lax '' when :warn Jekyll.logger.warn topic, error error when :strict Jekyll.logger.abort_with topic, error else raise Errors::UnkownErrorModeError, mode end end |
.normalized_attrs(attrs, prefix:, sep: '=') ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jekyll-diagrams/utils.rb', line 62 def normalized_attrs(attrs, prefix:, sep: '=') attrs = case attrs when String attrs when Array attrs.join(prefix) when Hash attrs.map { |k, v| "#{k}#{sep}#{v}" }.join(prefix) end "#{prefix}#{attrs}" end |
.run_jar(jar) ⇒ Object
58 59 60 |
# File 'lib/jekyll-diagrams/utils.rb', line 58 def run_jar(jar) "java -Djava.awt.headless=true -jar #{jar} " end |
.vendor_path(file = '') ⇒ Object
54 55 56 |
# File 'lib/jekyll-diagrams/utils.rb', line 54 def vendor_path(file = '') File.join(File.('../../vendor', __dir__), file) end |
.wrap_class(content, class_names) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/jekyll-diagrams/utils.rb', line 76 def wrap_class(content, class_names) <<~CONTENT <div class='#{Diagrams.config_name} diagrams #{class_names}'> #{content} </div> CONTENT end |