Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Last active August 29, 2015 14:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hopsoft/8cd3ddb94f9682f33f31 to your computer and use it in GitHub Desktop.
JavaScript Modules Tag Helper
# app/helpers/application_helper.rb
module ApplicationHelper
def javascript_modules_tag
paths = Dir[
Rails.root.join("app/assets/javascripts/modules/**/*"),
Rails.root.join("lib/assets/javascripts/modules/**/*"),
Rails.root.join("vendor/assets/javascripts/modules/**/*")
]
modules = paths.each_with_object({}) do |path, memo|
if File.file? path
name = path[path.rindex("modules/")..-1].split(".").first
memo[name.sub("modules/", "")] = javascript_path(name)
end
end
javascript_tag { "window.modules = #{modules.to_json}".html_safe }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment