Sha256: cc11fbdf3a47bc68e5d37353aceb7c635cb721822ddf0636e7362bf821cb7c12

Contents?: true

Size: 1.3 KB

Versions: 28

Compression:

Stored size: 1.3 KB

Contents

module Lookbook
  class Code::Component < Lookbook::BaseComponent
    def initialize(
      source: nil,
      language: :html,
      line_numbers: false,
      highlight_lines: [],
      start_line: 1,
      wrap: false,
      theme: nil,
      dark: false,
      full_height: false,
      **html_attrs
    )
      @source_code = source
      @highlight_opts = {
        language: language,
        line_numbers: line_numbers,
        highlight_lines: highlight_lines,
        start_line: start_line
      }
      @highlight_lines = highlight_lines
      @wrap = wrap
      @theme = theme
      @dark = dark
      @full_height = full_height
      super(**html_attrs)
    end

    def theme_classname
      "theme-#{@theme.to_s.tr("_", "-")}"
    end

    def source
      (@source_code || content).strip_heredoc.strip
    end

    def numbered?
      @highlight_opts[:line_numbers] == true
    end

    def focussed?
      @highlight_opts[:highlight_lines].any?
    end

    def full_height?
      @full_height
    end

    def is_dark?
      @dark
    end

    def before_render
      @theme ||= Lookbook.config.highlighter_options.fetch(:theme, :github).to_sym
      @dark ||= !!Lookbook.config.highlighter_options.fetch(:dark, false)
    end

    protected

    def alpine_component
      "codeComponent"
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lookbook-2.3.4 app/components/lookbook/code/component.rb
lookbook-2.3.3 app/components/lookbook/code/component.rb
lookbook-2.3.2 app/components/lookbook/code/component.rb
lookbook-2.3.0 app/components/lookbook/code/component.rb
lookbook-2.2.2 app/components/lookbook/code/component.rb
lookbook-2.2.1 app/components/lookbook/code/component.rb
lookbook-2.2.0 app/components/lookbook/code/component.rb
lookbook-2.1.1 app/components/lookbook/code/component.rb
lookbook-2.1.0 app/components/lookbook/code/component.rb
lookbook-2.0.5 app/components/lookbook/code/component.rb
lookbook-2.0.4 app/components/lookbook/code/component.rb
lookbook-2.0.3 app/components/lookbook/code/component.rb
lookbook-2.0.2 app/components/lookbook/code/component.rb
lookbook-2.0.1 app/components/lookbook/code/component.rb
lookbook-2.0.0 app/components/lookbook/code/component.rb
lookbook-2.0.0.rc.3 app/components/lookbook/code/component.rb
lookbook-2.0.0.rc.2 app/components/lookbook/code/component.rb
lookbook-2.0.0.rc.1 app/components/lookbook/code/component.rb
lookbook-2.0.0.beta.9 app/components/lookbook/code/component.rb
lookbook-2.0.0.beta.8 app/components/lookbook/code/component.rb