Class: Code::Component
- Inherits:
-
Lookbook::BaseComponent
- Object
- Lookbook::BaseComponent
- Code::Component
- Defined in:
- app/components/lookbook/code/component.rb
Instance Method Summary collapse
- #before_render ⇒ Object
- #focussed? ⇒ Boolean
- #full_height? ⇒ Boolean
-
#initialize(source: nil, language: :html, line_numbers: false, highlight_lines: [], start_line: 1, wrap: false, theme: nil, dark: false, full_height: false, **html_attrs) ⇒ Component
constructor
A new instance of Component.
- #is_dark? ⇒ Boolean
- #numbered? ⇒ Boolean
- #source ⇒ Object
- #theme_classname ⇒ Object
Constructor Details
#initialize(source: nil, language: :html, line_numbers: false, highlight_lines: [], start_line: 1, wrap: false, theme: nil, dark: false, full_height: false, **html_attrs) ⇒ Component
Returns a new instance of Component.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/components/lookbook/code/component.rb', line 3 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 |
Instance Method Details
#before_render ⇒ Object
54 55 56 57 |
# File 'app/components/lookbook/code/component.rb', line 54 def before_render @theme ||= Lookbook.config..fetch(:theme, :github).to_sym @dark ||= !!Lookbook.config..fetch(:dark, false) end |
#focussed? ⇒ Boolean
42 43 44 |
# File 'app/components/lookbook/code/component.rb', line 42 def focussed? @highlight_opts[:highlight_lines].any? end |
#full_height? ⇒ Boolean
46 47 48 |
# File 'app/components/lookbook/code/component.rb', line 46 def full_height? @full_height end |
#is_dark? ⇒ Boolean
50 51 52 |
# File 'app/components/lookbook/code/component.rb', line 50 def is_dark? @dark end |
#numbered? ⇒ Boolean
38 39 40 |
# File 'app/components/lookbook/code/component.rb', line 38 def numbered? @highlight_opts[:line_numbers] == true end |
#source ⇒ Object
34 35 36 |
# File 'app/components/lookbook/code/component.rb', line 34 def source (@source_code || content).strip_heredoc.strip end |
#theme_classname ⇒ Object
30 31 32 |
# File 'app/components/lookbook/code/component.rb', line 30 def theme_classname "theme-#{@theme.to_s.tr("_", "-")}" end |