simple_assets 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aa2f6fb75928fdccfa36eee3e4a31fb3abfd05aab4056733477c9c23cd774de5
4
+ data.tar.gz: 8489748d6fdbbbc7a1131d92383c6f371b0832b37bef59d8c2ec8e9264566361
5
+ SHA512:
6
+ metadata.gz: 28d3ce9d5003e143418af70041c9c312f3fc05da8050086765f103c6d4d1bbce8087f60698bf4d2a7c46898d84981345a44c9304fe344c06dbdb7f0568ecfa02
7
+ data.tar.gz: f299b6d924697b9ef0ae56ee0e96ccef29f67fc7e4d4a367773afb8436802d1d35433284e029ffa576f661b5b228b0a7bae5c6459c53303157dd4f2b24ef2913
@@ -0,0 +1,5 @@
1
+ CHANGELOG
2
+ ---------
3
+
4
+ - **0.1.0** - August 24, 2020
5
+ - Gem Initial Release
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2020 Weston Ganger
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,91 @@
1
+ # SimpleAssets
2
+
3
+ <a href="https://badge.fury.io/rb/simple_assets" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/simple_assets.svg" alt="Gem Version"></a>
4
+ <a href='https://travis-ci.com/westonganger/simple_assets' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://travis-ci.com/westonganger/simple_assets.svg?branch=master' border='0' alt='Build Status'></a>
5
+ <a href='https://rubygems.org/gems/simple_assets' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/simple_assets?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
6
+ <a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee'></a>
7
+
8
+
9
+ 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.
10
+
11
+ # Features
12
+
13
+ - Simplify your asset management in a sane way
14
+ - Promote Re-usability across Projects
15
+ - Works with any Ruby website generator or framework
16
+
17
+ # Installation
18
+
19
+ ```ruby
20
+ gem "simple_assets"
21
+ ```
22
+
23
+ # Usage
24
+
25
+ Create your asset definitions:
26
+
27
+ ```ruby
28
+ # config/initializers/simple_assets/my-asset.rb
29
+
30
+ SimpleAssets.add("my-asset") do |opts|
31
+ html = ""
32
+
33
+ if opts[:only] == "css"
34
+ html += <<~EOL
35
+ <link rel="stylesheet" href="#{ENV["CDN_URL"]}/my-asset/#{opts[:version]}/my-asset.min.css" />
36
+ EOL
37
+ end
38
+
39
+ if opts[:only] == "js"
40
+ html += <<~EOL
41
+ <script src="#{ENV["CDN_URL"]}/my-asset/#{opts[:version]}/my-asset.min.js"></script>
42
+
43
+ <script type"text/css">
44
+ $(document).on('ready', function(){
45
+ MyAsset.init();
46
+ });
47
+ </script>
48
+ EOL
49
+ end
50
+
51
+ html
52
+ end
53
+ ```
54
+
55
+ For another example definition please view the default [bootstrap asset definition](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/bootstrap.rb)
56
+
57
+ Note: I recommend using a seperate file for each asset so that its easy to copy custom assets from one project to another
58
+
59
+ Then in your view file call the following function:
60
+
61
+ ```erb
62
+ <%= SimpleAssets.render("my-asset", version: "1.0.0", foo: "bar") %>
63
+ ```
64
+
65
+ 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.
66
+
67
+ # Built-In Library Support
68
+
69
+ 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.
70
+
71
+ 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.
72
+
73
+ - [autosize](http://www.jacklmoore.com/autosize/) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/autosize.rb)
74
+ - [bootstrap](https://getbootstrap.com/) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/bootstrap.rb)
75
+ * Additional Options: `bootswatch_theme: "yeti"`
76
+ - [bulma](https://bulma.io/) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/bulma.rb)
77
+ - [chosen](https://github.com/harvesthq/chosen) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/chosen.rb)
78
+ - [font-awesome](https://fontawesome.com/) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/font-awesome.rb)
79
+ - [jquery](https://jquery.com/) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/jquery.rb)
80
+ - [jquery.tablesorter](https://github.com/Mottie/tablesorter) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/jquery.tablesorter.rb)
81
+ - [masonry](https://github.com/desandro/masonry) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/masonry.rb)
82
+ - [milligram](https://github.com/milligram/milligram) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/font-awesome.rb)
83
+ - [rails-ujs](https://github.com/rails/rails/tree/master/actionview/app/assets/javascripts) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/rails-ujs.rb)
84
+ - [turbolinks](https://github.com/turbolinks/turbolinks) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/turbolinks.rb)
85
+ - [x-editable](https://vitalets.github.io/x-editable/) - [View Source](https://github.com/westonganger/simple_assets/blob/master/lib/simple_assets/default_assets/x-editable.rb)
86
+
87
+ # Credits
88
+
89
+ Created & Maintained by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger)
90
+
91
+ [![Solid Foundation Web Development Logo](https://solidfoundationwebdev.com/logo-sm.png)](https://solidfoundationwebdev.com)
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/lib/simple_assets/version')
2
+ require 'bundler/gem_tasks'
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :console do
12
+ require 'simple_assets'
13
+
14
+ require 'irb'
15
+ binding.irb
16
+ end
17
+
18
+ task default: :test
@@ -0,0 +1,34 @@
1
+ require "simple_assets/version"
2
+
3
+ module SimpleAssets
4
+
5
+ class Error < StandardError; end
6
+
7
+ @@assets = {}
8
+
9
+ def self.add(name, &block)
10
+ @@assets[name] = block
11
+
12
+ return true
13
+ end
14
+
15
+ def self.render(name, opts={})
16
+ if @@assets[name]
17
+ str = @@assets[name].call(opts)
18
+ else
19
+ raise Error.new("Asset `#{name}` is not yet defined")
20
+ end
21
+
22
+ if str.respond_to?(:html_safe) && !str.html_safe?
23
+ str = str.html_safe
24
+ end
25
+
26
+ return str
27
+ end
28
+
29
+ end
30
+
31
+ ### Require Default Assets
32
+ Dir[File.join(__dir__, "simple_assets/default_assets/*.rb")].each do |f|
33
+ require "simple_assets/default_assets/#{f.split("/").last}"
34
+ end
@@ -0,0 +1,13 @@
1
+ SimpleAssets.add("autosize") do |opts|
2
+ <<~EOL
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/autosize.js/#{opts[:version] || "4.0.2"}/autosize.min.js"></script>
4
+
5
+ <script type="text/javascript">
6
+ $(document).on('turbolinks:load', function(){
7
+ var textarea = $("textarea:not(.no-autosize)");
8
+ textarea.prop('rows','3');
9
+ autosize(textarea);
10
+ });
11
+ </script>
12
+ EOL
13
+ end
@@ -0,0 +1,35 @@
1
+ SimpleAssets.add("bootstrap") do |opts|
2
+ html = ""
3
+
4
+ version = opts[:version] || "4.3.1"
5
+ major_version = version.to_s[0].to_i
6
+
7
+ if opts[:only] == "css"
8
+ if opts[:bootswatch_theme].present?
9
+ url = "//stackpath.bootstrapcdn.com/bootswatch/#{version}/#{bootswatch_theme}/bootstrap.min.css"
10
+ else
11
+ if major_version == 2
12
+ url = "//stackpath.bootstrapcdn.com/twitter-bootstrap/#{version}/css/bootstrap-combined.min.css"
13
+ else
14
+ url = "//stackpath.bootstrapcdn.com/bootstrap/#{version}/css/bootstrap.min.css"
15
+ end
16
+ end
17
+
18
+ html += %Q(<link rel="stylesheet" href="#{url}" />)
19
+ end
20
+
21
+ if opts[:only] == "js"
22
+ case major_version
23
+ when 2
24
+ url = "//stackpath.bootstrapcdn.com/twitter-bootstrap/#{version}/js/bootstrap.min.js"
25
+ when 3
26
+ url = "//stackpath.bootstrapcdn.com/bootstrap/#{version}/js/bootstrap.min.js"
27
+ else
28
+ url = "//stackpath.bootstrapcdn.com/bootstrap/#{version}/js/bootstrap.bundle.min.js"
29
+ end
30
+
31
+ html += %Q(<script src="#{url}"></script>)
32
+ end
33
+
34
+ html
35
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("bulma") do |opts|
2
+ <<~EOL
3
+ <link rel="stylesheet" src="https://cdnjs.cloudflare.com/ajax/libs/bulma/#{opts[:version] || "0.9.0"}/css/bulma.min.css">
4
+ EOL
5
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("chosen") do |opts|
2
+ <<~EOL
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/#{opts[:version] || '1.8.7'}/chosen.jquery.min.js"></script>
4
+ EOL
5
+ end
@@ -0,0 +1,11 @@
1
+ SimpleAssets.add("font-awesome") do |opts|
2
+ html = ""
3
+
4
+ if opts[:version].to_i >= 5
5
+ html += %Q(<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/#{opts[:version]}/css/all.css" />)
6
+ else
7
+ html += %Q(<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/#{opts[:version] || "4.7.0"}/css/font-awesome.min.css" />)
8
+ end
9
+
10
+ html
11
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("jquery") do |opts|
2
+ <<~EOL
3
+ "<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/#{opts[:version]}/jquery.min.js" ></script>"
4
+ EOL
5
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("jquery.tablesorter") do |opts|
2
+ <<~EOL
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/#{opts[:version] || '2.31.1'}/js/jquery.tablesorter.min.js"></script>
4
+ EOL
5
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("masonry") do |opts|
2
+ <<~EOL
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/#{opts[:version] || '4.2.2'}/masonry.pkgd.min.js"></script>
4
+ EOL
5
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("milligram") do |opts|
2
+ <<~EOL
3
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/#{opts[:version] || "1.3.0"}/milligram.min.css" />
4
+ EOL
5
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("rails-ujs") do |opts|
2
+ <<~EOL
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ujs/#{opts[:version] || '1.2.2'}/rails.min.js"></script>
4
+ EOL
5
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("turbolinks") do |opts|
2
+ <<~EOL
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/#{opts[:version] || '5.2.0'}/turbolinks.js"></script>
4
+ EOL
5
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAssets.add("x-editable") do |opts|
2
+ <<~EOL
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/x-editable/#{opts[:version] || '1.5.1'}/bootstrap-editable/js/bootstrap-editable.min.js"></script>
4
+ EOL
5
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleAssets
2
+ VERSION = "0.1.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Weston Ganger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Dead simple HTML-based assets helper for Ruby. The main idea here is
70
+ to promote re-usability for projects.
71
+ email: weston@westonganger.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CHANGELOG.md
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - lib/simple_assets.rb
81
+ - lib/simple_assets/default_assets/autosize.rb
82
+ - lib/simple_assets/default_assets/bootstrap.rb
83
+ - lib/simple_assets/default_assets/bulma.rb
84
+ - lib/simple_assets/default_assets/chosen.rb
85
+ - lib/simple_assets/default_assets/font-awesome.rb
86
+ - lib/simple_assets/default_assets/jquery.rb
87
+ - lib/simple_assets/default_assets/jquery.tablesorter.rb
88
+ - lib/simple_assets/default_assets/masonry.rb
89
+ - lib/simple_assets/default_assets/milligram.rb
90
+ - lib/simple_assets/default_assets/rails-ujs.rb
91
+ - lib/simple_assets/default_assets/turbolinks.rb
92
+ - lib/simple_assets/default_assets/x-editable.rb
93
+ - lib/simple_assets/version.rb
94
+ homepage: https://github.com/westonganger/simple_assets
95
+ licenses: []
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 1.9.3
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.1.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Dead simple HTML-based assets helper for Ruby. The main idea here is to promote
116
+ re-usability for projects.
117
+ test_files: []