assets_ledger 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4fbb22691f3c8c3e725f087148f40f605717605
4
+ data.tar.gz: e67a53c62d3d8ea5771b913bf04420962b07ac86
5
+ SHA512:
6
+ metadata.gz: cf99c44a78823903c7f85cc8e7806d53ae02a2958511838cff3c04048db7f4ffe4e55d31cdd5b5f4b0027b551b7ab9a0adf92458467833a91c00bd10df049e94
7
+ data.tar.gz: 3ef6735ce1baabcbe1773e85759c20a01f8a8b2a6cc46d81a59e1e3e3c4204a225bf23d1b99bc7d9f284210a9251874512210223188e72b09a23ae3546a94527
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in assets_ledger.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jacob Burenstam
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # AssetsLedger
2
+
3
+ Keep track of JS/CSS dependencies and makes sure they are only included once.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'assets_ledger'
11
+ ```
12
+
13
+ And then execute:
14
+ ```
15
+ $ bundle
16
+ ```
17
+ Or install it yourself as:
18
+ ```
19
+ $ gem install assets_ledger
20
+ ```
21
+ ## Usage
22
+
23
+ ```ruby
24
+ ledger = AssetsLedger::Ledger.new
25
+ ledger.add_js('path/to/js')
26
+ ledger.add_css('path/to/css')
27
+
28
+ # You can add many dependencies at once
29
+ ledger.add_js('/js/jquery.js', 'js/jquery.datatables.js')
30
+
31
+ # or pass an array
32
+ js_dependencies = ['/js/jquery.js', 'js/jquery.datatables.js']
33
+ ledger.add_js(js_dependencies)
34
+ ```
35
+
36
+ if you use Rails you can generate the include tags by:
37
+ ```
38
+ # In application.html.erb
39
+ stylesheet_link_tag *ledger.css_dependencies
40
+ # ...
41
+ javascript_include_tag *ledger.js_dependencies
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/trialbee/assets_ledger/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
Binary file
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'assets_ledger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'assets_ledger'
8
+ spec.version = AssetsLedger::VERSION
9
+ spec.authors = ['Jacob Burenstam', 'Albin Svensson']
10
+ spec.email = ['jacob.burenstam@trialbee.com', 'albin.svensson@trialbee.com']
11
+ spec.summary = %q{Keep track of JS/CSS dependencies and makes sure they are only included once.}
12
+ spec.description = 'Very simple way of handling JS/CSS dependencies and making sure they are present when needed but only included once.'
13
+ spec.homepage = 'https://github.com/trialbee/assets_ledger'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+ end
@@ -0,0 +1,5 @@
1
+ require 'assets_ledger/version'
2
+ require 'assets_ledger/ledger'
3
+
4
+ module AssetsLedger
5
+ end
@@ -0,0 +1,55 @@
1
+ module AssetsLedger
2
+ class Ledger
3
+ attr_reader :js_dependencies, :css_dependencies
4
+
5
+ def initialize
6
+ @js = Set.new
7
+ @css = Set.new
8
+ end
9
+
10
+ # Add JS to ledger
11
+ def add_js(*names)
12
+ @js.merge(dependencies_for(names, js_libs))
13
+ end
14
+
15
+ # Add CSS to ledger
16
+ def add_css(*names)
17
+ @css.merge(dependencies_for(names, css_libs))
18
+ end
19
+
20
+ # JS dependency list
21
+ # @return [Array] of JS dependencies.
22
+ def js_dependencies
23
+ @js.to_a
24
+ end
25
+
26
+ # CSS dependency list
27
+ # @return [Array] of CSS dependencies.
28
+ def css_dependencies
29
+ @css.to_a
30
+ end
31
+
32
+ # Returns a string with the source path for the given JS lib
33
+ # @return [String] JS source path.
34
+ # @param [Symbol] lib identifier
35
+ # @example Get JS source path for jQuery
36
+ # assets_ledger.js_source_for(:jquery)
37
+ def js_source_for(lib)
38
+ js_libs[lib]
39
+ end
40
+
41
+ protected
42
+
43
+ def dependencies_for(names, assets)
44
+ names.flatten.flat_map { |name| Array(assets[name] || name) }
45
+ end
46
+
47
+ def js_libs
48
+ {}
49
+ end
50
+
51
+ def css_libs
52
+ {}
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module AssetsLedger
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe AssetsLedger::Ledger do
5
+ let(:ledger) { described_class.new }
6
+ let(:string_dep) { 'page/test' }
7
+ let(:string_dep1) { 'page/test1' }
8
+
9
+ it 'adds library to list' do
10
+ expect(ledger.add_js(string_dep)).to eq(Set.new [string_dep])
11
+ end
12
+
13
+ it 'adds nothing if nil is passed as an argument' do
14
+ expect(ledger.add_js(nil)).to eq(Set.new [])
15
+ end
16
+
17
+ it 'adds library to list with multiple arguments' do
18
+ expect(ledger.add_js(string_dep, string_dep1)).to eq(Set.new [string_dep, string_dep1])
19
+ end
20
+
21
+ it 'adds library to list with argument as list' do
22
+ expect(ledger.add_js([string_dep, string_dep1])).to eq(Set.new [string_dep, string_dep1])
23
+ end
24
+
25
+ it 'has method to add css dependencies' do
26
+ expect(ledger.add_css(string_dep)).to eq(Set.new [string_dep])
27
+ end
28
+
29
+ it 'returns js dependencies as list' do
30
+ ledger.add_js(string_dep)
31
+ expect(ledger.js_dependencies).to eq([string_dep])
32
+ end
33
+
34
+ it 'returns css dependencies as list' do
35
+ ledger.add_css(string_dep)
36
+ expect(ledger.css_dependencies).to eq([string_dep])
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ require 'assets_ledger'
2
+
3
+ RSpec.configure do |config|
4
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assets_ledger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Burenstam
8
+ - Albin Svensson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-04-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Very simple way of handling JS/CSS dependencies and making sure they
57
+ are present when needed but only included once.
58
+ email:
59
+ - jacob.burenstam@trialbee.com
60
+ - albin.svensson@trialbee.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - assets_ledger-0.0.1.gem
72
+ - assets_ledger.gemspec
73
+ - lib/assets_ledger.rb
74
+ - lib/assets_ledger/ledger.rb
75
+ - lib/assets_ledger/version.rb
76
+ - spec/assets_ledger/ledger_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/trialbee/assets_ledger
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Keep track of JS/CSS dependencies and makes sure they are only included once.
102
+ test_files:
103
+ - spec/assets_ledger/ledger_spec.rb
104
+ - spec/spec_helper.rb
105
+ has_rdoc: