gjtorikian/html-pipeline

Missing context keys for HTML::Pipeline::EmojiFilter: :asset_root

marcocanderle opened this issue ยท 2 comments

Hi,

I'm with a Rails 5 application and adding html_pipeline gem with the EmojiFilter extension so that I can process the text sent by the users and filter the emojies.

I have the following:

def filtered_content
    pipeline = HTML::Pipeline.new [
     HTML::Pipeline::PlainTextInputFilter,
     HTML::Pipeline::MarkdownFilter,
     HTML::Pipeline::SanitizationFilter,
     HTML::Pipeline::AutolinkFilter,
     HTML::Pipeline::EmojiFilter
    ]
   pipeline.call(content)[:output].to_s
end

I followed the usual steps adding the gemoji gem so that I can use the EmojiFilter, but when I add it to the pipeline declaration and try to use the pipeline I get the error:

Missing context keys for HTML::Pipeline::EmojiFilter: :asset_root

I added this on my assets.rb initializer:

  Rails.application.config.assets.paths << Emoji.images_path
  Rails.application.config.assets.precompile << "emoji/**/*.png"

And also ran "rake emoji" but the error is still there.

Any ideas of I could solve this?

Thanks!
Marco

Hi! The asset_root is the base url to link emoji sprite, not related to Sprockets.

So you need to change your html-pipeline code:

def filtered_content
    pipeline = HTML::Pipeline.new [
     HTML::Pipeline::PlainTextInputFilter,
     HTML::Pipeline::MarkdownFilter,
     HTML::Pipeline::SanitizationFilter,
     HTML::Pipeline::AutolinkFilter,
     HTML::Pipeline::EmojiFilter
    ], { asset_root: "the url of your assets" } # <------
    # E.g. GitHub uses this: "https://assets-cdn.github.com/images/icons/emoji/unicode"
   pipeline.call(content)[:output].to_s
end

Hope this helps! ๐Ÿ˜Š

That's exactly what I was looking for!
Thanks a lot @JuanitoFatas

Perhaps that exact example could be on the readme file?

Thanks a lot for your help and for this gem!