0.0
No commit activity in last 3 years
No release in over 3 years
Dead simple HTML-based assets helper for Ruby. The main idea here is to promote re-usability for projects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

SimpleAssets

Gem Version Build Status RubyGems Downloads Buy Me a Coffee

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.

Credits

Created & Maintained by Weston Ganger - @westonganger

Solid Foundation Web Development Logo