chroma-js 0.0.1 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "chroma-js",
3
+ "version": "1.0.0",
4
+ "homepage": "https://github.com/schivei/chroma.js-rails",
5
+ "authors": [
6
+ "Elton Schivei Costa"
7
+ ],
8
+ "description": "This Gem is made to support the use of Chroma.js library with Rails Assets",
9
+ "main": [
10
+ "assets/javascripts/chroma.js"
11
+ ],
12
+ "keywords": [
13
+ "chroma-js",
14
+ "chroma.js",
15
+ "chroma",
16
+ "color",
17
+ "javascript"
18
+ ],
19
+ "license": "MIT",
20
+ "ignore": [
21
+ "**/.*",
22
+ "lib",
23
+ "templates",
24
+ "*.gemspec",
25
+ "Rakefile",
26
+ "Gemfile"
27
+ ]
28
+ }
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chroma-js/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "chroma-js"
8
+ s.version = Chroma::VERSION
9
+ s.authors = ["Elton Schivei Costa"]
10
+ s.email = ["costa@elton.schivei.nom.br"]
11
+ s.summary = "A Gem for Chroma.js library"
12
+ s.description = "This Gem is made to support the use of Chroma.js library with Rails Assets"
13
+ s.homepage = "https://github.com/schivei/chroma.js-rails"
14
+ s.license = "MIT"
15
+
16
+ s.add_runtime_dependency 'autoprefixer-rails', '~> 5.0'
17
+ s.add_development_dependency 'actionpack', '~> 4.1'
18
+ s.add_development_dependency 'activesupport', '~> 4.1'
19
+ s.add_development_dependency 'json', '~> 2.3'
20
+ s.add_development_dependency 'sprockets-rails', '~> 2.1'
21
+ s.add_development_dependency 'slim-rails', '~> 0'
22
+ s.add_development_dependency 'uglifier', '~> 0'
23
+ # Converter
24
+ s.add_development_dependency 'term-ansicolor', '~> 0'
25
+
26
+ s.rubyforge_project = "chroma-js"
27
+
28
+ s.files = `git ls-files`.split("\n")
29
+ end
@@ -1,26 +1,29 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'chroma.js/rails/version'
4
+ require 'chroma-js/version'
5
5
 
6
- Gem::Specification.new do |spec|
7
- spec.name = "chroma-js"
8
- spec.version = ChromaJS::Rails::VERSION
9
- spec.platform = Gem::Platform::RUBY
10
- spec.authors = ["Elton Schivei Costa"]
11
- spec.email = ["costa@elton.schivei.nom.br"]
12
- spec.summary = "A Gem for Chroma.js library"
13
- spec.description = "This Gem is made to support the use of Chroma.js library with Rails Assets"
14
- spec.homepage = "https://github.com/schivei/chroma.js-rails"
15
- spec.license = "MIT"
6
+ Gem::Specification.new do |s|
7
+ s.name = "chroma.js-rails"
8
+ s.version = Chroma::VERSION
9
+ s.authors = ["Elton Schivei Costa"]
10
+ s.email = ["costa@elton.schivei.nom.br"]
11
+ s.summary = "A Gem for Chroma.js library"
12
+ s.description = "This Gem is made to support the use of Chroma.js library with Rails Assets"
13
+ s.homepage = "https://github.com/schivei/chroma.js-rails"
14
+ s.license = "MIT"
16
15
 
17
- spec.required_rubygems_version = ">= 1.3.6"
18
- spec.rubyforge_project = "chroma-js"
16
+ s.add_runtime_dependency 'autoprefixer-rails', '~> 5.0'
17
+ s.add_development_dependency 'actionpack', '~> 4.1'
18
+ s.add_development_dependency 'activesupport', '~> 4.1'
19
+ s.add_development_dependency 'json', '~> 2.3'
20
+ s.add_development_dependency 'sprockets-rails', '~> 2.1'
21
+ s.add_development_dependency 'slim-rails', '~> 0'
22
+ s.add_development_dependency 'uglifier', '~> 0'
23
+ # Converter
24
+ s.add_development_dependency 'term-ansicolor', '~> 0'
19
25
 
20
- spec.files = `git ls-files`.split("\n")
26
+ s.rubyforge_project = "chroma-js"
21
27
 
22
- spec.add_dependency "railties", ">= 3.1"
23
- spec.add_development_dependency "rails", ">= 3.1"
24
-
25
- spec.require_paths = ["lib", "vendor"]
28
+ s.files = `git ls-files`.split("\n")
26
29
  end
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "schivei/chroma-js",
3
+ "version": "1.0.1",
4
+ "description": "This Gem is made to support the use of Chroma.js library with Rails Assets",
5
+ "keywords": [
6
+ "chroma-js",
7
+ "chroma.js",
8
+ "chroma",
9
+ "color",
10
+ "javascript"
11
+ ],
12
+ "homepage": "https://github.com/schivei/chroma.js-rails",
13
+ "authors": [
14
+ {
15
+ "name": "Elton Schivei Costa",
16
+ "email": "costa@elton.schivei.nom.br"
17
+ }
18
+ ],
19
+ "support": {
20
+ "issues": "https://github.com/schivei/chroma.js-rails/issues"
21
+ },
22
+ "license": "MIT",
23
+ "extra": {
24
+ "branch-alias": {
25
+ "dev-master": "0.1.x-dev"
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,47 @@
1
+ require 'chroma-js/version'
2
+ module Chroma
3
+ class << self
4
+ # Based on bootstrap-sass
5
+ def load!
6
+ if rails?
7
+ register_rails_engine
8
+ elsif sprockets?
9
+ register_sprockets
10
+ end
11
+ end
12
+
13
+ # Paths
14
+ def gem_path
15
+ @gem_path ||= File.expand_path '..', File.dirname(__FILE__)
16
+ end
17
+
18
+ def javascripts_path
19
+ File.join assets_path, 'javascripts'
20
+ end
21
+
22
+ def assets_path
23
+ @assets_path ||= File.join gem_path, 'assets'
24
+ end
25
+
26
+ # Environment detection helpers
27
+ def sprockets?
28
+ defined?(::Sprockets)
29
+ end
30
+
31
+ def rails?
32
+ defined?(::Rails)
33
+ end
34
+
35
+ private
36
+
37
+ def register_rails_engine
38
+ require 'chroma-js/engine'
39
+ end
40
+
41
+ def register_sprockets
42
+ Sprockets.append_path(javascripts_path)
43
+ end
44
+ end
45
+ end
46
+
47
+ Chroma.load!
@@ -0,0 +1,11 @@
1
+ module Chroma
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ initializer 'chroma-js.assets.precompile' do |app|
5
+ %w(javascripts).each do |sub|
6
+ app.config.assets.paths << root.join('assets', sub).to_s
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Chroma
2
+ VERSION = '1.0.7'
3
+ CHROMA_SHA = '65c0852b050b58147cff5de5157f061bdabf2bc4'
4
+ end
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "chroma-js",
3
+ "version": "1.0.1",
4
+ "homepage": "https://github.com/schivei/chroma.js-rails",
5
+ "main": "assets/javascripts/chroma.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git://github.com/schivei/chroma.js-rails"
9
+ },
10
+ "keywords": [
11
+ "chroma-js",
12
+ "chroma.js",
13
+ "chroma",
14
+ "color",
15
+ "javascript"
16
+ ],
17
+ "contributors": [
18
+ "Elton Schivei Costa"
19
+ ],
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/schivei/chroma.js-rails/issues"
23
+ }
24
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "chrome-js",
3
+ "description": "This Gem is made to support the use of Chroma.js library with Rails Assets",
4
+ "tags": [
5
+ "chroma-js",
6
+ "chroma.js",
7
+ "chroma",
8
+ "color",
9
+ "javascript"
10
+ ]
11
+ }
@@ -0,0 +1,28 @@
1
+ require 'find'
2
+ require 'json'
3
+ require 'pathname'
4
+
5
+ namespace :bower do
6
+
7
+ find_files = ->(path) {
8
+ Find.find(Pathname.new(path).relative_path_from(Pathname.new Dir.pwd).to_s).map do |path|
9
+ path if File.file?(path)
10
+ end.compact
11
+ }
12
+
13
+ desc 'update main and version in bower.json'
14
+ task :generate do
15
+ require 'bootstrap-sass'
16
+ Dir.chdir Bootstrap.gem_path do
17
+ spec = JSON.parse(File.read 'bower.json')
18
+
19
+ spec['main'] = %w(assets/javascripts/chroma.js)
20
+
21
+ spec['version'] = Chroma::VERSION
22
+
23
+ File.open('bower.json', 'w') do |f|
24
+ f.puts JSON.pretty_generate(spec)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,74 @@
1
+ # coding: utf-8
2
+ # Based on convert script from vwall/compass-twitter-bootstrap gem.
3
+ # https://github.com/vwall/compass-twitter-bootstrap/blob/master/build/convert.rb
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this work except in compliance with the License.
7
+ # You may obtain a copy of the License in the LICENSE file, or at:
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'open-uri'
18
+ require 'json'
19
+ require 'strscan'
20
+ require 'forwardable'
21
+ require 'term/ansicolor'
22
+ require 'fileutils'
23
+
24
+ require_relative 'converter/js_conversion'
25
+ require_relative 'converter/logger'
26
+ require_relative 'converter/network'
27
+
28
+ class Converter
29
+ extend Forwardable
30
+ include Network
31
+ include LessConversion
32
+ include JsConversion
33
+ include FontsConversion
34
+
35
+ def initialize(repo: 'gka/chroma.js', branch: 'master', save_to: {}, cache_path: 'tmp/converter-cache-chroma')
36
+ @logger = Logger.new
37
+ @repo = repo
38
+ @branch = branch || 'master'
39
+ @branch_sha = get_branch_sha
40
+ @cache_path = cache_path
41
+ @repo_url = "https://github.com/#@repo"
42
+ @save_to = {
43
+ js: 'assets/javascripts/chroma'}.merge(save_to)
44
+ end
45
+
46
+ def_delegators :@logger, :log, :log_status, :log_processing, :log_transform, :log_file_info, :log_processed, :log_http_get_file, :log_http_get_files, :silence_log
47
+
48
+ def process_chroma
49
+ log_status "Convert Chroma LESS to Sass"
50
+ puts " repo : #@repo_url"
51
+ puts " branch : #@branch_sha #@repo_url/tree/#@branch"
52
+ puts " save to: #{@save_to.to_json}"
53
+ puts " twbs cache: #{@cache_path}"
54
+ puts '-' * 60
55
+
56
+ @save_to.each { |_, v| FileUtils.mkdir_p(v) }
57
+
58
+ process_javascript_assets
59
+ store_version
60
+ end
61
+
62
+ def save_file(path, content, mode='w')
63
+ dir = File.dirname(path)
64
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
65
+ File.open(path, mode) { |file| file.write(content) }
66
+ end
67
+
68
+ # Update version.rb file with CHROMA_SHA
69
+ def store_version
70
+ path = 'lib/chroma-js/version.rb'
71
+ content = File.read(path).sub(/CHROMA_SHA\s*=\s*['"][\w]+['"]/, "CHROMA_SHA = '#@branch_sha'")
72
+ File.open(path, 'w') { |f| f.write(content) }
73
+ end
74
+ end
@@ -0,0 +1,38 @@
1
+ # regular string scanner works with bytes
2
+ # this one works with chars and provides #scan_next
3
+ class Converter
4
+ class CharStringScanner
5
+ extend Forwardable
6
+
7
+ def initialize(*args)
8
+ @s = StringScanner.new(*args)
9
+ end
10
+
11
+ def_delegators :@s, :scan_until, :skip_until, :string
12
+
13
+ # advance scanner to pos after the next match of pattern and return the match
14
+ def scan_next(pattern)
15
+ return unless @s.scan_until(pattern)
16
+ @s.matched
17
+ end
18
+
19
+ def pos
20
+ byte_to_str_pos @s.pos
21
+ end
22
+
23
+ def pos=(i)
24
+ @s.pos = str_to_byte_pos i
25
+ i
26
+ end
27
+
28
+ private
29
+
30
+ def byte_to_str_pos(pos)
31
+ @s.string.byteslice(0, pos).length
32
+ end
33
+
34
+ def str_to_byte_pos(pos)
35
+ @s.string.slice(0, pos).bytesize
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ class Converter
2
+ module JsConversion
3
+ def process_javascript_assets
4
+ log_status 'Processing javascripts...'
5
+ save_to = @save_to[:js]
6
+ contents = {}
7
+ read_files('js', chroma_js_files).each do |name, file|
8
+ contents[name] = file
9
+ save_file("#{save_to}/#{name}", file)
10
+ end
11
+ log_processed "#{chroma_js_files * ' '}"
12
+
13
+ log_status 'Updating javascript manifest'
14
+ manifest = ''
15
+ chroma_js_files.each do |name|
16
+ name = name.gsub(/\.js$/, '')
17
+ manifest << "//= require ./chroma/#{name}\n"
18
+ end
19
+ dist_js = read_files('dist/js', %w(chroma.js chroma.min.js))
20
+ {
21
+ 'assets/javascripts/chroma.js' => dist_js['chroma.js'],
22
+ 'assets/javascripts/chroma.min.js' => dist_js['chroma.min.js'],
23
+ }.each do |path, content|
24
+ save_file path, content
25
+ log_processed path
26
+ end
27
+ end
28
+
29
+ def chroma_js_files
30
+ @chroma_js_files ||= begin
31
+ files = get_paths_by_type('js', /\.js$/).reject { |path| path =~ %r(^tests/) }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ class Converter
2
+ class Logger
3
+ include Term::ANSIColor
4
+
5
+ def log_status(status)
6
+ puts bold status
7
+ end
8
+
9
+ def log_file_info(s)
10
+ puts " #{magenta s}"
11
+ end
12
+
13
+ def log_transform(*args, from: caller[1][/`.*'/][1..-2].sub(/^block in /, ''))
14
+ puts " #{cyan from}#{cyan ": #{args * ', '}" unless args.empty?}"
15
+ end
16
+
17
+ def log_processing(name)
18
+ puts yellow " #{File.basename(name)}"
19
+ end
20
+
21
+ def log_processed(name)
22
+ puts green " #{name}"
23
+ end
24
+
25
+ def log_http_get_file(url, cached = false)
26
+ s = " #{'CACHED ' if cached}GET #{url}..."
27
+ if cached
28
+ puts dark green s
29
+ else
30
+ puts dark cyan s
31
+ end
32
+ end
33
+
34
+ def log_http_get_files(files, from, cached = false)
35
+ return if files.empty?
36
+ s = " #{'CACHED ' if cached}GET #{files.length} files from #{from} #{files * ' '}..."
37
+ if cached
38
+ puts dark green s
39
+ else
40
+ puts dark cyan s
41
+ end
42
+ end
43
+
44
+ def puts(*args)
45
+ STDERR.puts *args unless @silence
46
+ end
47
+
48
+ alias log puts
49
+
50
+ def silence_log
51
+ @silence = true
52
+ yield
53
+ ensure
54
+ @silence = false
55
+ end
56
+ end
57
+ end