Skip to content

Instantly share code, notes, and snippets.

@jeremyruppel
Created June 10, 2013 19:24
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jeremyruppel/5751461 to your computer and use it in GitHub Desktop.
Save jeremyruppel/5751461 to your computer and use it in GitHub Desktop.
Inline asset helpers for middleman.
module AssetHelper
##
# Renders a stylesheet asset inline.
def inline_stylesheet( name )
content_tag :style do
sprockets[ "#{name}.css" ].to_s
end
end
##
# Renders a javascript asset inline.
def inline_javascript( name )
content_tag :script do
sprockets[ "#{name}.js" ].to_s
end
end
end
!!!
%html{ html_attrs }
%head
= inline_stylesheet 'application'
= inline_javascript 'application'
/ ...
@bithavoc
Copy link

❤️

as easy as just adding the following snippet in config.rb:

module AssetHelper
  ##
  # Renders a stylesheet asset inline.
  def inline_stylesheet(name)
    content_tag :style do
      sprockets["#{name}.css"].to_s
    end
  end

  ##
  # Renders a javascript asset inline.
  def inline_javascript(name)
    content_tag :script do
      sprockets["#{name}.js"].to_s
    end
  end
end

helpers AssetHelper

works with middleman 4 💪

@damirkotoric
Copy link

Thank you @bithavoc. Also, worth mentioning that one needs to install https://github.com/middleman/middleman-sprockets to use the above code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment