Sha256: 651a90065be20502b6db068d0416b9182a2fc0bad3240663cc0c23540f14f0be

Contents?: true

Size: 1.09 KB

Versions: 24

Compression:

Stored size: 1.09 KB

Contents

module Lookbook
  class Code::Component < Lookbook::BaseComponent
    include Lookbook::OutputHelper

    def initialize(
      source: nil,
      language: :html,
      line_numbers: false,
      highlight_lines: [],
      start_line: 1,
      wrap: false,
      theme: :github_light,
      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
      @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 == true
    end

    protected

    def alpine_component
      "codeComponent"
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
lookbook-1.3.1 app/components/lookbook/code/component.rb
lookbook-1.3.0 app/components/lookbook/code/component.rb
lookbook-1.2.1 app/components/lookbook/code/component.rb
lookbook-1.2.0 app/components/lookbook/code/component.rb
lookbook-1.1.1 app/components/lookbook/code/component.rb
lookbook-1.1.0 app/components/lookbook/code/component.rb
lookbook-1.0.8 app/components/lookbook/code/component.rb
lookbook-1.0.7 app/components/lookbook/code/component.rb
lookbook-1.0.6 app/components/lookbook/code/component.rb
lookbook-1.0.5 app/components/lookbook/code/component.rb
lookbook-1.0.4 app/components/lookbook/code/component.rb
lookbook-1.0.3 app/components/lookbook/code/component.rb
lookbook-1.0.2 app/components/lookbook/code/component.rb
lookbook-1.0.1 app/components/lookbook/code/component.rb
lookbook-1.0.0 app/components/lookbook/code/component.rb
lookbook-1.0.0.rc.3 app/components/lookbook/code/component.rb
lookbook-1.0.0.rc.2 app/components/lookbook/code/component.rb
lookbook-1.0.0.rc.1 app/components/lookbook/code/component.rb
lookbook-1.0.0.beta.8 app/components/lookbook/code/component.rb
lookbook-1.0.0.beta.7 app/components/lookbook/code/component.rb