Class: Redactor4Input
- Inherits:
-
SimpleForm::Inputs::TextInput
- Object
- SimpleForm::Inputs::TextInput
- Redactor4Input
- Defined in:
- app/inputs/redactor4_input.rb
Overview
Custom SimpleForm input for Redactor 4 WYSIWYG editor
Uses Stimulus controller for lazy loading and proper Turbo lifecycle handling
Usage:
<%= f.input :body, as: :redactor4 %>
<%= f.input :body, as: :redactor4, mode: :blog %> # Blog mode with AI Tools
<%= f.input :body, as: :redactor4, mode: :email %> # Email template mode
<%= f.input :body, as: :redactor4, ai: true %> # Enable AI Tools explicitly
Options:
- mode: Editor mode (:classic, :blog, :email) - default: :classic
- ai: Enable AI Tools (default: false, auto-enabled for :blog mode)
- min_height: Custom minimum height (default: '300px')
- max_height: Custom maximum height (e.g. '70vh', 'false' for unlimited)
- air: Enable air mode (floating toolbar)
Modes:
- :classic - Standard editor without AI
- :blog - Blog post editor with AI Tools enabled
- :email - Email template editor with merge tags, clips, etc.
Instance Method Summary collapse
Instance Method Details
#input(wrapper_options = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/inputs/redactor4_input.rb', line 25 def input( = nil) = (, ) # Extract our custom options before passing to the text_area mode = .delete(:mode)&.to_sym || :classic enable_ai = .delete(:ai) # Add Stimulus target attribute [:data] ||= {} [:data][:redactor4_init_target] = 'editor' # Add form-control class for Bootstrap styling [:class] = Array([:class]) [:class] << 'form-control' unless [:class].include?('form-control') # Build Stimulus controller data attributes controller_data = { controller: 'redactor4-init' } # Set mode-specific values case mode when :email controller_data[:redactor4_init_email_value] = true when :blog controller_data[:redactor4_init_blog_value] = true # Blog mode automatically enables AI unless explicitly disabled enable_ai = true if enable_ai.nil? end # Explicit AI override (can force AI on in classic mode or off in blog mode) if enable_ai == true && mode != :blog controller_data[:redactor4_init_blog_value] = true # AI requires blog mode end # Support for custom options passed via input_html controller_data[:redactor4_init_min_height_value] = .delete(:min_height) if [:min_height] if .key?(:max_height) mh = .delete(:max_height) controller_data[:redactor4_init_max_height_value] = (mh == false ? 'false' : mh.to_s) end controller_data[:redactor4_init_air_value] = .delete(:air) if [:air] # Source code (HTML) editing - enabled for: # - Blog mode (always enabled for content editors) # - Admins (full access) # - Marketing managers (need to paste/edit raw HTML for blog posts) can_use_source = mode == :blog || template.current_account&.is_admin? || template.current_account&.is_marketing_manager? controller_data[:redactor4_init_source_value] = can_use_source || false # Wrap textarea in a div with the Stimulus controller template.tag.div(data: controller_data) do @builder.text_area(attribute_name, ) end end |
#input_html_classes ⇒ Object
83 84 85 |
# File 'app/inputs/redactor4_input.rb', line 83 def input_html_classes super end |