SimpleAssets
Dead simple HTML-based assets helper for Ruby. The main idea is to promote re-usability between projects. Great for Static Site Generators, Apps, Rails Engines, etc.
Features
- Simplify your asset management in a sane way
- Promote Re-usability across Projects
- Works with any Ruby website generator or framework
Installation
gem "simple_assets"
Usage
Create your asset definitions:
# config/initializers/simple_assets/my-asset.rb
SimpleAssets.add("my-asset") do |opts|
html = ""
if opts[:only] == "css"
html += <<~EOL
<link rel="stylesheet" href="#{ENV["CDN_URL"]}/my-asset/#{opts[:version]}/my-asset.min.css" />
EOL
end
if opts[:only] == "js"
html += <<~EOL
<script src="#{ENV["CDN_URL"]}/my-asset/#{opts[:version]}/my-asset.min.js"></script>
<script type"text/javascript">
$(document).on('ready', function(){
MyAsset.init();
});
</script>
EOL
end
html
end
For another example definition please view the default bootstrap asset definition
Note: I recommend using a seperate file for each asset so that its easy to copy custom assets from one project to another
Then in your view file call the following function:
<%= SimpleAssets.render("my-asset", version: "1.0.0", foo: "bar") %>
Note: When SimpleAssets.render
is called the lambda/proc is called using .call
. It does not cache the output string so as to enable for more dynamic usage.
Built-In Library Support
In an effort to save time and energy this gem comes bundled with a small default set of libraries that I think every application could benefit from. These defaults can easily be overwritten using the SimpleAssets.add
method.
Please create an issue if you truly feel another library should be included here. Please note that this library does not target any specific Ruby framework or site generator, so only recommend libraries that apply to all possible use-cases.
- autosize - View Source
-
bootstrap - View Source
- Additional Options:
bootswatch_theme: "yeti"
- Additional Options:
- bulma - View Source
- chosen - View Source
- font-awesome - View Source
- jquery - View Source
- jquery.tablesorter - View Source
- masonry - View Source
- milligram - View Source
- rails-ujs - View Source
- turbolinks - View Source
Credits
Created & Maintained by Weston Ganger - @westonganger