Module: Coradoc::Html::Config
- Defined in:
- lib/coradoc/html/config.rb
Constant Summary collapse
- DEFAULT_LANG =
'en'- DEFAULT_TITLE =
'Untitled'- DEFAULT_OPTIONS =
{ theme: :classic, modern: { color_scheme: :glass, primary_color: '#6366f1', accent_color: '#8b5cf6', max_width: '1200px', content_width: '65ch', sidebar_width: '280px', theme_toggle: true, reading_progress: true, back_to_top: true, toc_sticky: true, copy_code_buttons: true, enable_animations: true, animation_duration: '300ms', lazy_load_images: true }.freeze, html_version: :html5, pretty_print: false, indent: ' ', line_wrap: 0, escape_content: true, preserve_whitespace: false, convert_line_breaks: true, preserve_comments: false, use_semantic_elements: true, add_css_classes: true, add_data_attributes: false, external_link_target: nil, link_rel: nil, image_loading: nil, image_decoding: nil, syntax_highlighter: nil, syntax_highlighter_opts: {}, table_border: false, table_stripes: false, preserve_custom_attributes: true, attribute_prefix: 'data-', stylesheet: 'coradoc.css', stylesdir: './css', linkcss: false, copycss: true, css_theme: 'professional', custom_css: nil, javascript: 'coradoc.js', jsdir: './js', linkjs: false, theme_toggle: true, toc_interactive: nil, author: nil, description: nil, keywords: nil, lang: 'en', embedded: false, meta_tags: {}, toc: false, toclevels: 2, toc_title: 'Table of Contents', toc_placement: :auto, sectnums: false, sectnumlevels: 3, source_highlighter: nil, highlightjs_theme: 'github', pygments_style: 'default', rouge_style: 'github' }.freeze
- ASSET_METHODS =
%i[ stylesheet_path embedded_stylesheet resolve_css_imports css_link_tag css_style_tag custom_css_tag embed_css? css_tags javascript_path embedded_javascript js_link_tag js_script_tag embed_js? js_tags syntax_highlighter_tags highlightjs_tags ].freeze
Class Method Summary collapse
- .code_block_attributes(language, options = {}) ⇒ Object
- .css_class_for(element_type, role = nil) ⇒ Object
- .data_attribute_name(name, prefix: 'data-') ⇒ Object
- .default_options ⇒ Object
- .element_config(element_type, options = {}) ⇒ Object
- .html_tag_for(element_type) ⇒ Object
- .merge_options(user_options = {}) ⇒ Object
- .theme_toggle?(options = {}) ⇒ Boolean
- .toc_interactive?(options = {}) ⇒ Boolean
- .validate_options(options) ⇒ Object
Class Method Details
.code_block_attributes(language, options = {}) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/coradoc/html/config.rb', line 117 def code_block_attributes(language, = {}) attrs = {} attrs[:class] = "language-#{language}" if language && !language.empty? attrs[:class] = [attrs[:class], 'line-numbers'].compact.join(' ') if [:linenums] || [:line_numbers] attrs end |
.css_class_for(element_type, role = nil) ⇒ Object
95 96 97 98 99 |
# File 'lib/coradoc/html/config.rb', line 95 def css_class_for(element_type, role = nil) classes = [element_type.to_s.tr('_', '-')] classes << role if role classes.join(' ') end |
.data_attribute_name(name, prefix: 'data-') ⇒ Object
101 102 103 |
# File 'lib/coradoc/html/config.rb', line 101 def data_attribute_name(name, prefix: 'data-') "#{prefix}#{name.to_s.tr('_', '-')}" end |
.default_options ⇒ Object
78 79 80 |
# File 'lib/coradoc/html/config.rb', line 78 def DEFAULT_OPTIONS.dup end |
.element_config(element_type, options = {}) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/coradoc/html/config.rb', line 105 def element_config(element_type, = {}) { tag: html_tag_for(element_type), css_class: css_class_for(element_type, [:role]), attributes: [:attributes] || {} } end |
.html_tag_for(element_type) ⇒ Object
113 114 115 |
# File 'lib/coradoc/html/config.rb', line 113 def html_tag_for(element_type) TagMapping.tag_for(element_type) end |
.merge_options(user_options = {}) ⇒ Object
82 83 84 |
# File 'lib/coradoc/html/config.rb', line 82 def ( = {}) .merge() end |
.theme_toggle?(options = {}) ⇒ Boolean
126 127 128 |
# File 'lib/coradoc/html/config.rb', line 126 def theme_toggle?( = {}) .fetch(:theme_toggle, DEFAULT_OPTIONS[:theme_toggle]) end |
.toc_interactive?(options = {}) ⇒ Boolean
130 131 132 133 134 |
# File 'lib/coradoc/html/config.rb', line 130 def toc_interactive?( = {}) toc_enabled = .fetch(:toc, DEFAULT_OPTIONS[:toc]) toc_interactive = [:toc_interactive] toc_interactive.nil? ? toc_enabled : toc_interactive end |
.validate_options(options) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/coradoc/html/config.rb', line 86 def () valid_keys = DEFAULT_OPTIONS.keys invalid_keys = .keys - valid_keys raise ArgumentError, "Invalid options: #{invalid_keys.join(', ')}" unless invalid_keys.empty? end |