module EditModeRails::ActionViewExtensions::EditModeHelper
Public Instance Methods
api_root_url()
click to toggle source
# File lib/editmode-rails/action_view_extensions/editmode_helper.rb, line 12 def api_root_url ENV["EDITMODE_OVERRIDE_API_URL"] || "https://www.editmode.app/api" end
api_version()
click to toggle source
# File lib/editmode-rails/action_view_extensions/editmode_helper.rb, line 8 def api_version "v1" end
bit(label,identifier,options={})
click to toggle source
# File lib/editmode-rails/action_view_extensions/editmode_helper.rb, line 60 def bit(label,identifier,options={}) chunk_display(label,identifier) end
chunk(label,identifier,options={})
click to toggle source
# File lib/editmode-rails/action_view_extensions/editmode_helper.rb, line 64 def chunk(label,identifier,options={}) chunk_display(label,identifier) end
chunk_display(label,identifier,options={})
click to toggle source
# File lib/editmode-rails/action_view_extensions/editmode_helper.rb, line 20 def chunk_display(label,identifier,options={}) chunk_content = Rails.cache.fetch("bit_#{identifier}") do url = "#{versioned_api_url}/bits/#{identifier}" response = HTTParty.get(url) chunk_content = response['content'] end display_type = options[:display_type] || "span" css_class = options[:css_class] content_type = "plain" # Simple check to see if returned chunk contains html. Regex will need to be improved if /<[a-z][\s\S]*>/i.match(chunk_content) content_type = "rich" chunk_content = chunk_content.html_safe elsif chunk_content.include? "\n" content_type = "rich" renderer = Redcarpet::Render::HTML.new(no_links: true, hard_wrap: true) markdown = Redcarpet::Markdown.new(renderer, extensions = {}) chunk_content = markdown.render(chunk_content).html_safe end case display_type when "span" if content_type == "rich" content_tag(:span, :class => css_class, :data => {:chunk => identifier, :chunk_editable => false }) do chunk_content end else content_tag(:span, :class => css_class, :data => {:chunk => identifier, :chunk_editable => true }) do chunk_content end end when "raw" chunk_content end end
raw_chunk(label,identifier,options={})
click to toggle source
# File lib/editmode-rails/action_view_extensions/editmode_helper.rb, line 68 def raw_chunk(label,identifier,options={}) chunk_display(label,identifier,options.merge(:display_type => "raw")) end
versioned_api_url()
click to toggle source
# File lib/editmode-rails/action_view_extensions/editmode_helper.rb, line 16 def versioned_api_url "#{api_root_url}/#{api_version}" end