Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Helpers #61

Open
KonnorRogers opened this issue Apr 23, 2023 · 0 comments
Open

Form Helpers #61

KonnorRogers opened this issue Apr 23, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@KonnorRogers
Copy link
Owner

Create form helpers courtesy of @afomera

require "action_view/helpers/tags/placeholderable"

module ActionView::Helpers
  class Tags::RhinoEditor < Tags::Base
    include Tags::Placeholderable

    def render
      options = @options.stringify_keys
      options["value"] = options.fetch("value") { value&.to_trix_html }
      add_default_name_and_id(options)

      @template_object.rhino_editor_tag(options["name"], options["value"], options.except("value"))
    end
  end

  module FormHelper
    def rhino_editor_field(object_name, method, options = {})
      Tags::RhinoEditor.new(object_name, method, self, options).render
    end
  end

  class FormBuilder
    def rhino_editor(method, options = {})
      @template.rhino_editor_field(@object_name, method, objectify_options(options))
    end
  end
end


module TagHelper
  cattr_accessor(:id, instance_accessor: false) { 0 }

  include Rails.application.routes.url_helpers

  def rhino_editor_tag(name, value = nil, options = {})
    options = options.symbolize_keys

    content_tag("div") do
      hidden_field_tag(name, value) +
       tag("rhino-editor", { input: options[:id], data: { "blob-url-template": rails_service_blob_url(":signed_id", ":filename"), "direct-upload-url": rails_direct_uploads_url } }.merge(options))
    end
  end
end
@KonnorRogers KonnorRogers added the enhancement New feature or request label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant