Class: Inkpen::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/inkpen/configuration.rb

Overview

Global configuration for Inkpen.

The Configuration class holds default settings that apply to all editor instances. Individual editors can override these defaults.

Examples:

Basic configuration

Inkpen.configure do |config|
  config.toolbar = :floating
  config.extensions = [:bold, :italic, :link, :slash_commands]
  config.placeholder = "Start writing..."
end

Enable all extensions

Inkpen.configure do |config|
  config.extensions = config.all_extensions
end

See Also:

Author:

  • Nauman Tariq

Since:

  • 0.1.0

Constant Summary collapse

CORE_EXTENSIONS =

Core text formatting extensions included by default.

These provide basic rich text editing capabilities.

Returns:

  • (Array<Symbol>)

    list of core extension names

Since:

  • 0.1.0

%i[
  bold
  italic
  strike
  underline
  highlight
  link
  heading
  bullet_list
  ordered_list
  blockquote
  code_block
  horizontal_rule
  hard_break
  typography
].freeze
ADVANCED_EXTENSIONS =

Advanced extensions for enhanced editing features.

These provide Notion-like capabilities including databases, drag & drop, slash commands, and export functionality.

Returns:

  • (Array<Symbol>)

    list of advanced extension names

Since:

  • 0.1.0

%i[
  image
  table
  advanced_table
  inkpen_table
  slash_commands
  mention
  emoji
  search_replace
  footnotes
  placeholder
  typography
  highlight
  underline
  subscript
  superscript
  youtube
  character_count
  code_block_syntax
  task_list
  section
  document_section
  preformatted
  block_gutter
  drag_handle
  toggle_block
  columns
  callout
  block_commands
  enhanced_image
  file_attachment
  embed
  table_of_contents
  database
  export_commands
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize configuration with sensible defaults.

Since:

  • 0.1.0



130
131
132
133
134
135
136
137
138
# File 'lib/inkpen/configuration.rb', line 130

def initialize
  @toolbar = :floating          # :floating, :fixed, :none
  @extensions = CORE_EXTENSIONS.dup
  @placeholder = "Start writing..."
  @autosave = false
  @autosave_interval = 5000     # milliseconds
  @min_height = "200px"
  @max_height = nil
end

Instance Attribute Details

#autosaveBoolean

Returns whether autosave is enabled by default.

Returns:

  • (Boolean)

    whether autosave is enabled by default



50
51
52
53
54
55
56
# File 'lib/inkpen/configuration.rb', line 50

attr_accessor :toolbar,
:extensions,
:placeholder,
:autosave,
:autosave_interval,
:min_height,
:max_height

#autosave_intervalInteger

Returns autosave interval in milliseconds.

Returns:

  • (Integer)

    autosave interval in milliseconds



50
51
52
53
54
55
56
# File 'lib/inkpen/configuration.rb', line 50

attr_accessor :toolbar,
:extensions,
:placeholder,
:autosave,
:autosave_interval,
:min_height,
:max_height

#extensionsArray<Symbol>

Returns list of enabled extensions.

Returns:

  • (Array<Symbol>)

    list of enabled extensions



50
51
52
53
54
55
56
# File 'lib/inkpen/configuration.rb', line 50

attr_accessor :toolbar,
:extensions,
:placeholder,
:autosave,
:autosave_interval,
:min_height,
:max_height

#max_heightString?

Returns maximum editor height (CSS value).

Returns:

  • (String, nil)

    maximum editor height (CSS value)



50
51
52
53
54
55
56
# File 'lib/inkpen/configuration.rb', line 50

attr_accessor :toolbar,
:extensions,
:placeholder,
:autosave,
:autosave_interval,
:min_height,
:max_height

#min_heightString?

Returns minimum editor height (CSS value).

Returns:

  • (String, nil)

    minimum editor height (CSS value)



50
51
52
53
54
55
56
# File 'lib/inkpen/configuration.rb', line 50

attr_accessor :toolbar,
:extensions,
:placeholder,
:autosave,
:autosave_interval,
:min_height,
:max_height

#placeholderString

Returns placeholder text for empty editors.

Returns:

  • (String)

    placeholder text for empty editors



50
51
52
53
54
55
56
# File 'lib/inkpen/configuration.rb', line 50

attr_accessor :toolbar,
:extensions,
:placeholder,
:autosave,
:autosave_interval,
:min_height,
:max_height

#toolbarSymbol

Returns toolbar style (:floating, :fixed, :none).

Returns:

  • (Symbol)

    toolbar style (:floating, :fixed, :none)



50
51
52
# File 'lib/inkpen/configuration.rb', line 50

def toolbar
  @toolbar
end

Instance Method Details

#all_extensionsArray<Symbol>

Get all available extensions (core + advanced).

Returns:

  • (Array<Symbol>)

    all extension names

Since:

  • 0.1.0



171
172
173
# File 'lib/inkpen/configuration.rb', line 171

def all_extensions
  CORE_EXTENSIONS + ADVANCED_EXTENSIONS
end

#disable_extension(name) ⇒ Symbol?

Disable a specific extension.

Examples:

config.disable_extension(:bold)

Parameters:

  • name (Symbol, String)

    the extension name to disable

Returns:

  • (Symbol, nil)

    the removed extension or nil

Since:

  • 0.1.0



162
163
164
# File 'lib/inkpen/configuration.rb', line 162

def disable_extension(name)
  @extensions.delete(name.to_sym)
end

#enable_extension(name) ⇒ Array<Symbol>

Enable a specific extension.

Examples:

config.enable_extension(:slash_commands)

Parameters:

  • name (Symbol, String)

    the extension name to enable

Returns:

  • (Array<Symbol>)

    updated list of extensions

Since:

  • 0.1.0



149
150
151
# File 'lib/inkpen/configuration.rb', line 149

def enable_extension(name)
  @extensions << name.to_sym unless @extensions.include?(name.to_sym)
end