fauve 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62e3905a46d1054c308be5dda7bb4c41d3371eac
4
+ data.tar.gz: 1cc8599130f0f3240e1ee16e2e9ed4745ee5863a
5
+ SHA512:
6
+ metadata.gz: 8ed476915a985221daba2f9fddb42fcce17e02d584029fb89b59f39460e946799e9834392a582df187a352a9dbcba7701ac47b88f8e600ad48ed0344cbd1098c
7
+ data.tar.gz: a4e0e32cbe55744dd9fbd95749a8bb0b7ea3d5c4f3c3d058bce490a165fd63778eaa3c8d1b656eed541182c24e32051a00611f13a4fa0c9c544fabdcd68b6c20
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *sublime-project
19
+ *sublime-workspace
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --profile
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fauve.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'codeclimate-test-reporter', '~> 0.1', require: false
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Daniel Angel-Bradford
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.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Fauve
2
+
3
+ [![Build Status](https://travis-ci.org/clouseauu/fauve.svg?branch=master)](https://travis-ci.org/clouseauu/fauve)
4
+ [![Code Climate](https://codeclimate.com/github/clouseauu/fauve/badges/gpa.svg)](https://codeclimate.com/github/clouseauu/fauve)
5
+ [![Test Coverage](https://codeclimate.com/github/clouseauu/fauve/badges/coverage.svg)](https://codeclimate.com/github/clouseauu/fauve)
6
+ [![Dependencies](https://gemnasium.com/clouseauu/fauve.svg)](https://gemnasium.com/clouseauu/fauve)
7
+
8
+ Fauve is a Rails/Sass gem to help you manage your app's colour schemes.
9
+
10
+ Have you had to scour through a sizeable app's CSS/SCSS/Sass files to change hard-coded colour hex values because you're re-branding? Have you ended up with a `colors.sass` or similar file with 1000 lines of variables? Solving this problem is Fauve's _raison d'être_.
11
+
12
+ ## The basic premise
13
+
14
+ As a rule of thumb, you want to work with about five colours when selecting a scheme. You can have fewer, but when you have _too many_, that's when maintenance becomes nightmarish.
15
+
16
+ Fauve allows you to have a basic set of colours and define variations to use in different scenarios.
17
+
18
+ ## Usage
19
+
20
+ 1. Add a `fauve.yml` file under `config` in your rails app:
21
+
22
+ ```yaml
23
+ ---
24
+ scheme:
25
+ - '#131210'
26
+ - '#c05d33'
27
+ - '#e5b455'
28
+ - '#3c8399'
29
+ - '#d8ccb2'
30
+
31
+ links:
32
+ main_text: scheme[1]
33
+ main_hover: scheme[1]
34
+
35
+ buttons:
36
+ main_bg: scheme[3]
37
+ main_text: scheme[0]
38
+ success_bg: scheme[3]
39
+
40
+ odd_case:
41
+ main: '#4de3ef'
42
+ ```
43
+
44
+ 2. Reference the colours in your SCSS/Sass files by calling the `fauve` function, passing `section` and `key`:
45
+
46
+ ```sass
47
+ .button
48
+ background: fauve(buttons, main_bg)
49
+ color: fauve(buttons, main_text)
50
+ padding: 20px
51
+ ...
52
+ ```
53
+
54
+ You can also use number keys to reference your colours if you use Array syntax, so the config file above references `scheme` as:
55
+
56
+ ```sass
57
+ .button
58
+ background: fauve(scheme, 3)
59
+ color: fauve(scheme, 2)
60
+ padding: 20px
61
+ ...
62
+ ```
63
+
64
+ Furthermore, you may add any number of Sass colour filters using the following syntax:
65
+
66
+ ```sass
67
+ .button
68
+ background: fauve(buttons, main_bg, $darken: 20, $rgba: .5)
69
+ color: fauve(buttons, main_text, $lighten: 5)
70
+ padding: 20px
71
+ ...
72
+ ```
73
+
74
+
75
+ ## Installation
76
+
77
+ Add this line to your application's Gemfile:
78
+
79
+ gem 'fauve'
80
+
81
+ And then execute:
82
+
83
+ $ bundle
84
+
85
+ Or install it yourself as:
86
+
87
+ $ gem install fauve
88
+
89
+
90
+ ## TODO
91
+
92
+ - [ ] Allow filtering (colour mixing) in yaml file
93
+ - [ ] Generate colour scheme page
94
+ - [ ] [Combustion](https://github.com/pat/combustion) testing
95
+ - [ ] Rationale as to why this is a better approach to SassScript Maps
96
+ - [ ] A logo
97
+
98
+
99
+ ## License ([MIT](https://en.wikipedia.org/wiki/MIT_License))
100
+
101
+ Copyright (c) 2015
102
+
103
+ 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:
104
+
105
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
106
+
107
+ 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.
108
+
109
+ ## Contributing
110
+
111
+ 1. Fork it
112
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: :spec
7
+ rescue LoadError
8
+ end
data/bin/fauve ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fauve/cli'
4
+
5
+ fauve = Fauve::CLI.run
6
+ exit(1) unless fauve
data/fauve.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fauve/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'fauve'
8
+ s.version = Fauve::VERSION
9
+ s.authors = ['Daniel Angel-Bradford', 'Timothy Dang']
10
+ s.email = ['locusdelicti@gmail.com', 'timothyqd@gmail.com']
11
+ s.description = %q{Fauve lets you manage your app's colour scheme}
12
+ s.summary = %q{Fauve lets you manage your app's colour scheme}
13
+ s.homepage = ''
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ['lib']
20
+ s.required_ruby_version = '~> 2'
21
+
22
+ s.add_dependency 'sass', '>= 3.1.10'
23
+ s.add_dependency 'rails', '>= 4.1'
24
+ s.add_dependency 'slim'
25
+ s.add_dependency 'railties'
26
+ s.add_dependency 'sprockets-rails', '>= 2.1'
27
+ s.add_dependency 'trollop'
28
+
29
+ s.add_development_dependency 'bundler', '~> 1.3'
30
+ s.add_development_dependency 'rspec-rails', '>= 3.1'
31
+ s.add_development_dependency 'rake'
32
+ s.add_development_dependency 'pry'
33
+ s.add_development_dependency 'awesome_print'
34
+
35
+ end
data/lib/fauve/cli.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'trollop'
2
+ require 'rails'
3
+
4
+ module Fauve
5
+
6
+ #fauve -o x/y/x.html [rails/public] -i x/y/z.yml [rails/config/fauve.xml] -v [variations default true]
7
+
8
+ module CLI
9
+
10
+ def run
11
+ end
12
+
13
+ module_function :run
14
+
15
+ def options
16
+ # Trollop::options do
17
+ # opt :output, "Output", :type => :string, :default => ( defined?(Rails) ? Rails.public_path.to_s : "./" )
18
+ # opt :input, "Input", :type => :string, :default => ( defined?(Rails) ? "#{Rails.root}/config" : "./" )
19
+ # opt :skip_variations, "Skip variations", :short => "-v"
20
+ # end
21
+ end
22
+ module_function :options
23
+
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,24 @@
1
+ module Fauve
2
+
3
+ # Representation of a colour_scheme.
4
+ # Holds a raw colour map as well as the current section,
5
+ # reference and colour
6
+
7
+ class ColourScheme
8
+
9
+ attr_accessor :colour
10
+ alias_method :to_s, :colour
11
+
12
+ def initialize(map: Fauve::Config::colour_map, section_name: :app, reference_name: 0)
13
+ @colour_map = Fauve::Scheme::ColourMap.new(map)
14
+ @section = Fauve::Scheme::Section.new(colour_map, section_name)
15
+ @reference = Fauve::Scheme::Reference.new(reference_name)
16
+ @colour = Fauve::Scheme::Colour.new(colour_map, section, reference).colour
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :section, :reference, :colour_map
22
+
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module Fauve
2
+
3
+ module Config
4
+
5
+ def self.colour_map
6
+ YAML.load_file Fauve::Rails::Railtie.config.fauve.config_file
7
+ end
8
+
9
+ end
10
+
11
+ end
12
+
@@ -0,0 +1,41 @@
1
+ module Fauve
2
+
3
+ # Interface for Fauve to talk to Sass.
4
+ # Applies filters and returns Sass-Object colours
5
+ # Requires Fauve::Scheme::ColourMap, Fauve::Scheme::Section
6
+ # and Fauve::Scheme::Reference
7
+
8
+ class Engine
9
+
10
+ attr_reader :colour
11
+
12
+ def initialize(context: Sass::Script::Functions::EvaluationContext.new({}), raw_colour: raw_colour, filters: {})
13
+ @sass_context = context
14
+ @filters = filters
15
+ @raw_colour = raw_colour
16
+ @colour = sass_colour
17
+ run_filters
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :filters, :sass_context, :raw_colour
23
+
24
+ def sass_colour
25
+ Sass::Script::Color.new to_rgb
26
+ end
27
+
28
+ def to_rgb
29
+ raw_colour.scan(/^#(..?)(..?)(..?)$/).first.map {|num| num.ljust(2, num).to_i(16)}
30
+ end
31
+
32
+ def run_filters
33
+ # binding.pry
34
+ filters.keys.each do |filter|
35
+ @colour = sass_context.send filter.to_sym, colour, filters[filter]
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,10 @@
1
+ # Error for undefined sections in yaml file
2
+ class Fauve::UndefinedSectionError < StandardError; end
3
+ # Error for undefined references in yaml file
4
+ class Fauve::UndefinedReferenceError < StandardError; end
5
+ # Error for invalid references in yaml file
6
+ class Fauve::InvalidReferenceError < StandardError; end
7
+ # Error for circular references in yaml file
8
+ class Fauve::CircularReferenceError < StandardError; end
9
+ # Error for syntax issues in yaml file
10
+ class Fauve::SyntaxError < StandardError; end
@@ -0,0 +1,35 @@
1
+ module Sass
2
+ module Script
3
+ module Functions
4
+
5
+ declare(:fauve, [:section, :reference], var_kwargs: true)
6
+
7
+ def fauve(section, reference, filters = {})
8
+ @fauve_section = section
9
+ @fauve_reference = reference
10
+ @fauve_filters = filters
11
+ engine_colour
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :fauve_section, :fauve_reference, :fauve_filters
17
+
18
+ def raw_colour
19
+ Fauve::ColourScheme.new(
20
+ map: Fauve::Config::colour_map,
21
+ section_name: fauve_section,
22
+ reference_name: fauve_reference
23
+ ).to_s
24
+ end
25
+
26
+ def engine_colour
27
+ Fauve::Engine.new(
28
+ context: self,
29
+ raw_colour: raw_colour,
30
+ filters: fauve_filters
31
+ ).colour
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ module Fauve::Rails
2
+
3
+ # Tie Fauve options to Rails.
4
+
5
+ class Railtie < ::Rails::Railtie
6
+ config.fauve = ActiveSupport::OrderedOptions.new
7
+
8
+ initializer :fauve_setup do |app|
9
+ config.fauve.config_file = File.join(Rails.root, 'config/fauve.yml') unless config.fauve.config_file
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,79 @@
1
+ module Fauve
2
+ module Scheme
3
+
4
+ # Representation of a colour as part of a wider scheme.
5
+ # Holds a raw colour and a colour with filters applied.
6
+ # Requires Fauve::Scheme::ColourMap, Fauve::Scheme::Section
7
+ # and Fauve::Scheme::Reference
8
+
9
+ class Colour
10
+
11
+ @@candidates = []
12
+
13
+ attr_reader :filters, :raw_colour
14
+
15
+ def initialize(colour_map, section, reference)
16
+ @colour_map = colour_map
17
+ @section = section
18
+ @reference = reference
19
+ @candidate = operations.shift
20
+ @filters = operations
21
+ @raw_colour = determine_raw_colour
22
+ end
23
+
24
+ def colour
25
+ raw_colour
26
+ end
27
+
28
+ private
29
+
30
+ HEX_COLOUR_REGEX = /^#(?:[0-9a-fA-F]{3}){1,2}$/
31
+ REFERENCE_REGEX = /\[([a-z_]|[0-9])+\]/
32
+ SECTION_NAME_REGEX = /[^\[]+/
33
+ REFERENCE_NAME_REGEX = /\[(.*?)\]/
34
+
35
+ attr_reader :colour_map, :section, :reference, :operations, :candidate
36
+
37
+ def determine_raw_colour
38
+ return candidate if is_valid_hex_colour?
39
+ while references_another_section? do
40
+ resolve(candidate)
41
+ end
42
+ @@candidates = []
43
+ candidate
44
+ end
45
+
46
+ def resolve(colour)
47
+ raise Fauve::CircularReferenceError.new('Circular reference detected') if @@candidates.include?(colour)
48
+ @@candidates << colour
49
+ @candidate = recursed(colour).raw_colour
50
+ end
51
+
52
+ def recursed(colour)
53
+ self.class.new(colour_map, source_section(colour), source_reference(colour))
54
+ end
55
+
56
+ def source_section(key)
57
+ section.class.new(colour_map, key[SECTION_NAME_REGEX])
58
+ end
59
+
60
+ def source_reference(key)
61
+ reference.class.new(key.match(REFERENCE_NAME_REGEX)[1])
62
+ end
63
+
64
+ def operations
65
+ @operations ||= section.to_h[reference.key].split(',').collect{ |element| element.strip }
66
+ rescue
67
+ raise Fauve::UndefinedReferenceError.new("Reference isn't a valid index or key")
68
+ end
69
+
70
+ def is_valid_hex_colour?
71
+ HEX_COLOUR_REGEX === candidate
72
+ end
73
+
74
+ def references_another_section?
75
+ REFERENCE_REGEX === candidate
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,18 @@
1
+ module Fauve
2
+ module Scheme
3
+
4
+ # Representation of a colour map as part of a wider scheme.
5
+ # Holds the colour map hash as defined in the options yaml file
6
+
7
+ class ColourMap
8
+
9
+ attr_reader :map
10
+
11
+ def initialize(map)
12
+ @map = map
13
+ end
14
+
15
+ private
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ module Fauve
2
+ module Scheme
3
+
4
+ # Representation of a reference as part of a wider scheme.
5
+ # Holds a reference, which can be an integer, a string or a
6
+ # reference to another section[ref] as a string in the form
7
+ # "scheme[1]" or "buttons[main_text]"
8
+ # depending on how the config yaml file has been defined.
9
+
10
+ class Reference
11
+
12
+ def initialize(reference_name)
13
+ @reference_name = reference_name.to_s
14
+ end
15
+
16
+ def key
17
+ case
18
+ when reference_is_digit?
19
+ reference_name.to_i
20
+ when reference_is_valid_string?
21
+ reference_name.to_s
22
+ else
23
+ raise Fauve::InvalidReferenceError.new("Reference isn't a valid index or key")
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ DIGIT_KEY_REGEX = /^[0-9]*$/
30
+ ALPHANUMERIC_KEY_REGEX = /^[a-z]+[a-zA-Z0-9\-_]+$/
31
+
32
+ attr_reader :reference_name
33
+
34
+ def reference_is_digit?
35
+ DIGIT_KEY_REGEX === reference_name
36
+ end
37
+
38
+ def reference_is_valid_string?
39
+ ALPHANUMERIC_KEY_REGEX === reference_name
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ module Fauve
2
+ module Scheme
3
+
4
+ # Representation of a section key as part of a wider scheme.
5
+ # Holds a section name, which points to a top-level key within
6
+ # a colour scheme.
7
+ # Takes a Fauve::Scheme::ColourMap and a section name (string)
8
+
9
+ class Section
10
+
11
+ attr_reader :name
12
+
13
+ def initialize(colour_map, name)
14
+ @colour_map = colour_map
15
+ @name = name.to_s
16
+ end
17
+
18
+ def to_h
19
+ return colour_map.map[name] if section_exists?
20
+ raise Fauve::UndefinedSectionError.new('Section is not referenced in config')
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :colour_map
26
+
27
+ def section_exists?
28
+ !!colour_map.map[name]
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Fauve
2
+ VERSION = "0.0.7"
3
+ end
data/lib/fauve.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'fauve/version'
2
+ require 'fauve/errors'
3
+ require 'fauve/config'
4
+
5
+ if defined? Rails
6
+ require 'sprockets/railtie'
7
+ require 'fauve/engine'
8
+ require 'fauve/scheme/colour_map'
9
+ require 'fauve/scheme/section'
10
+ require 'fauve/scheme/reference'
11
+ require 'fauve/scheme/colour'
12
+ require 'fauve/colour_scheme'
13
+ require 'fauve/railtie'
14
+ require 'fauve/helpers'
15
+ end
16
+
17
+ module Fauve
18
+ module Rails
19
+ end
20
+ end
21
+
@@ -0,0 +1,29 @@
1
+ scheme:
2
+ - '#131210'
3
+ - '#c05d33'
4
+ - '#e5b455'
5
+ - '#3c8399'
6
+ - '#d8ccb2'
7
+
8
+ forms:
9
+ main_bg: '#f60'
10
+ alternate_bg: '#9cde0d'
11
+ main_text: '#5af8de'
12
+
13
+ links:
14
+ main_text: scheme[1]
15
+ main_hover: scheme[1], lighten=10, hue=20
16
+ invalid_ref: scheme[7]
17
+ circular_1: links[circular_2]
18
+ circular_2: links[circular_1]
19
+
20
+ buttons:
21
+ main_bg: scheme[3]
22
+ main_text: scheme[2]
23
+ success_bg: scheme[3], darken=10
24
+
25
+ multi_level:
26
+ level: buttons[main_text]
27
+
28
+ odd_case:
29
+ main: '#4de3ef'
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ module Fauve
4
+
5
+ describe ColourScheme do
6
+
7
+ let(:map) { YAML.load_file File.expand_path("./spec/fixtures/fauve.yml") }
8
+ let(:section_name) { :scheme }
9
+ let(:reference_name) { 2 }
10
+
11
+ subject { described_class.new( map: map, section_name: section_name, reference_name: reference_name ) }
12
+
13
+ describe '#initialize' do
14
+ it 'instantiates a full colour scheme' do
15
+ expect(subject).to respond_to :colour
16
+ end
17
+ end
18
+
19
+ describe '#colour' do
20
+
21
+ context 'when using integers as a reference' do
22
+ let(:reference_name) { 3 }
23
+
24
+ it 'interprets primary colour correctly' do
25
+ expect(subject.colour).to eq "#3c8399"
26
+ end
27
+ end
28
+
29
+ context 'when using keys as a reference' do
30
+ let(:section_name) { :forms }
31
+ let(:reference_name) { :main_text }
32
+
33
+ it 'interprets primary colour correctly' do
34
+ expect(subject.colour).to eq "#5af8de"
35
+ end
36
+ end
37
+
38
+ context 'when referencing a multi-level tree' do
39
+ let(:section_name) { :multi_level }
40
+ let(:reference_name) { :level }
41
+
42
+ context 'when the reference is valid' do
43
+ it 'interprets the colour correctly' do
44
+ expect(subject.colour).to eq '#e5b455'
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Fauve
4
+ describe Config do
5
+
6
+ let(:config_file) { File.expand_path("./spec/fixtures/fauve.yml") }
7
+
8
+ before do
9
+ allow(Fauve::Rails::Railtie.config.fauve).to receive(:config_file).and_return(config_file)
10
+ end
11
+
12
+ subject { described_class }
13
+
14
+ describe '.colour_map' do
15
+ it 'returns a hashified colour scheme' do
16
+ expect(subject.colour_map).to be_a Hash
17
+ end
18
+
19
+ it 'includes all sections' do
20
+ expect(subject.colour_map).to have_key 'scheme'
21
+ expect(subject.colour_map).to have_key 'forms'
22
+ expect(subject.colour_map).to have_key 'links'
23
+ expect(subject.colour_map).to have_key 'buttons'
24
+ expect(subject.colour_map).to have_key 'multi_level'
25
+ expect(subject.colour_map).to have_key 'odd_case'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fauve::Engine do
4
+
5
+ let(:sass_context) { Sass::Script::Functions::EvaluationContext.new( Sass::Environment.new ) }
6
+ let(:amount) { Sass::Script::Number.new(20) }
7
+ let(:filters) { Hash.new }
8
+ let(:raw_colour) { "#ff69b3" }
9
+
10
+ let(:engine) { Fauve::Engine.new(
11
+ context: sass_context,
12
+ raw_colour: raw_colour,
13
+ filters: filters
14
+ )
15
+ }
16
+
17
+ before :each do
18
+ engine.colour.options = {}
19
+ end
20
+
21
+ describe "#colour" do
22
+
23
+ it 'returns a base colour in the form of a SASS colour object' do
24
+ expect(engine.colour).to be_an_instance_of Sass::Script::Color
25
+ end
26
+
27
+ context "when applied filters" do
28
+
29
+ let(:filters) { { "lighten" => amount, "saturate" => amount } }
30
+
31
+ it 'applies said filters and returns the correct colour' do
32
+ expect(engine.colour.to_s).to eq "#ffcfe7"
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Sass
4
+ module Script
5
+ describe Functions do
6
+
7
+ let(:config) { YAML.load_file File.expand_path("./spec/fixtures/fauve.yml") }
8
+ let(:section) { :scheme }
9
+ let(:filters) { Hash.new }
10
+ let(:reference) { 3 }
11
+
12
+ before do
13
+ allow(Fauve::Config).to receive(:colour_map).and_return(config)
14
+ end
15
+
16
+ subject { FauveFunction.new }
17
+
18
+ describe '#fauve' do
19
+ it 'returns a Sass colour' do
20
+ expect(subject.fauve(section, reference)).to be_a Sass::Script::Value::Color
21
+ end
22
+
23
+ it 'returns the right colour' do
24
+ colour = subject.fauve(section, reference)
25
+ colour.options = {}
26
+ expect(colour.to_s).to eq '#3c8399'
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ # Dummy class for testing the module
35
+ class FauveFunction; include Sass::Script::Functions; end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ # TODO: This is a bit meh. We need something like combustion to properly test
4
+ # the gem inside a rails application.
5
+
6
+ module Fauve
7
+ module Rails
8
+ describe Railtie do
9
+
10
+ let(:config_file) { File.expand_path("./spec/fixtures/fauve.yml") }
11
+
12
+ subject { described_class }
13
+
14
+ context 'config' do
15
+ it 'ties to Rails config' do
16
+ expect(subject.config.fauve).to be_a ActiveSupport::OrderedOptions
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ module Fauve
4
+ module Scheme
5
+ describe Colour do
6
+
7
+ let(:config) { YAML.load_file File.expand_path("./spec/fixtures/fauve.yml") }
8
+ let(:colour_map) { Fauve::Scheme::ColourMap.new(config) }
9
+ let(:section_name) { :scheme }
10
+ let(:section) { Fauve::Scheme::Section.new(colour_map, section_name) }
11
+ let(:reference) { Fauve::Scheme::Reference.new(reference_name) }
12
+
13
+ subject { described_class.new( colour_map, section, reference ) }
14
+
15
+ describe '#initialize' do
16
+ context 'when passed filters' do
17
+ let(:section_name) { :links }
18
+ let(:reference_name) { :main_hover }
19
+
20
+ it 'correctly interprets filters' do
21
+ expect(subject.filters).to be_a Array
22
+ expect(subject.filters.length).to eq 2
23
+ end
24
+ end
25
+
26
+ context 'when not passed filters' do
27
+ let(:section_name) { :links }
28
+ let(:reference_name) { :main_text }
29
+
30
+ it 'correctly interprets filters' do
31
+ expect(subject.filters).to be_empty
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#raw_colour' do
37
+ context "when using integers in the reference" do
38
+ let(:reference_name) { 0 }
39
+
40
+ it 'interprets primary colour correctly' do
41
+ expect(subject.raw_colour).to eq "#131210"
42
+ end
43
+
44
+ context "when invoking other integers" do
45
+ let(:reference_name) { 2 }
46
+
47
+ it 'interprets colours in the scheme correctly' do
48
+ expect(subject.raw_colour).to eq "#e5b455"
49
+ end
50
+ end
51
+
52
+ context "when invoking the last existing integer" do
53
+ let(:reference_name) { 4 }
54
+
55
+ it 'interprets the colour correctly' do
56
+ expect(subject.raw_colour).to eq "#d8ccb2"
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'when using keys' do
62
+ let(:section_name) { :forms }
63
+ let(:reference_name) { :main_bg }
64
+
65
+ it 'interprets primary colour correctly' do
66
+ expect(subject.raw_colour).to eq "#f60"
67
+ end
68
+
69
+ context "when invoking other keys" do
70
+ let(:reference_name) { :alternate_bg }
71
+
72
+ it 'interprets colours in the scheme correctly' do
73
+ expect(subject.raw_colour).to eq "#9cde0d"
74
+ end
75
+ end
76
+
77
+ context 'when invoking the last existing key' do
78
+ let(:reference_name) { :main_text }
79
+
80
+ it 'interprets the colour correctly' do
81
+ expect(subject.raw_colour).to eq '#5af8de'
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'when referencing another section' do
87
+ let(:section_name) { :links }
88
+ let(:reference_name) { :main_text }
89
+
90
+ context 'when the reference is valid' do
91
+ it 'interprets the colour correctly' do
92
+ expect(subject.raw_colour).to eq '#c05d33'
93
+ end
94
+ end
95
+
96
+ context 'when the reference is invalid' do
97
+ let(:reference_name) { :invalid_red }
98
+ it 'raises an UndefinedReference error' do
99
+ expect{ subject }.to raise_exception Fauve::UndefinedReferenceError
100
+ end
101
+ end
102
+
103
+ context 'when the reference is circular' do
104
+ let(:reference_name) { :circular_1 }
105
+ it 'raises a CircularReferenceError error' do
106
+ expect{ subject }.to raise_exception Fauve::CircularReferenceError
107
+ end
108
+ end
109
+ end
110
+
111
+ context 'when passed incorrect / non-existent references' do
112
+ let(:section_name) { :scheme }
113
+
114
+ context 'with integers' do
115
+ let(:reference_name) { 10 }
116
+
117
+ it 'raises an UndefinedReference error' do
118
+ expect{ subject }.to raise_exception Fauve::UndefinedReferenceError
119
+ end
120
+ end
121
+
122
+ context 'with keys' do
123
+ let(:reference_name) { :a_non_declared_key }
124
+
125
+ it 'raises an UndefinedReference error' do
126
+ expect{ subject }.to raise_exception Fauve::UndefinedReferenceError
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ module Fauve
4
+ module Scheme
5
+ describe Reference do
6
+
7
+ subject { described_class.new(reference_name) }
8
+
9
+ describe '#key' do
10
+
11
+ context 'when the reference is numeric' do
12
+ let(:reference_name) { '1' }
13
+
14
+ it 'returns an integer' do
15
+ expect( subject.key ).to eq 1
16
+ end
17
+ end
18
+
19
+ context 'when the reference is a key' do
20
+
21
+ context 'with an invalid key' do
22
+ let(:reference_name) { 'like oh my god yo!' }
23
+
24
+ it 'raises an InvalidReferenceError error' do
25
+ expect{ subject.key }.to raise_exception Fauve::InvalidReferenceError
26
+ end
27
+ end
28
+
29
+ context 'with a valid symbol key' do
30
+ let(:reference_name) { :a_valid_key }
31
+
32
+ it 'returns the key' do
33
+ expect( subject.key ).to eq 'a_valid_key'
34
+ end
35
+ end
36
+
37
+ context 'with a valid string key' do
38
+ let(:reference_name) { 'another_valid_key' }
39
+
40
+ it 'returns the key' do
41
+ expect( subject.key ).to eq 'another_valid_key'
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ module Fauve
4
+ module Scheme
5
+ describe Section do
6
+
7
+ let(:section_name) { 'i_like_bananas' }
8
+ let(:config) { YAML.load_file File.expand_path("./spec/fixtures/fauve.yml") }
9
+ let(:colour_map) { Fauve::Scheme::ColourMap.new(config) }
10
+
11
+ subject { described_class.new(colour_map, section_name) }
12
+
13
+ describe '#initialize' do
14
+ it 'exposes the section name' do
15
+ expect(subject.name).to eq section_name
16
+ end
17
+ end
18
+
19
+ describe '#to_h' do
20
+
21
+ context 'when the section exists' do
22
+ let(:section_name) { :odd_case }
23
+
24
+ it 'returns the section hash' do
25
+ expect(subject.to_h).to eq({ 'main' => '#4de3ef' })
26
+ end
27
+ end
28
+
29
+ context 'when the section does not exist' do
30
+ let(:section_name) { 'i_like_bananas' }
31
+
32
+ it 'returns the section hash' do
33
+ expect{subject.to_h}.to raise_exception Fauve::UndefinedSectionError
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'pry'
5
+ require 'sass'
6
+ require 'yaml'
7
+ require 'sprockets/railtie'
8
+ require 'fauve/config'
9
+ require 'fauve/railtie'
10
+ require 'fauve/errors'
11
+ require 'fauve/engine'
12
+ require 'fauve/scheme/colour_map'
13
+ require 'fauve/scheme/section'
14
+ require 'fauve/scheme/reference'
15
+ require 'fauve/scheme/colour'
16
+ require 'fauve/colour_scheme'
17
+ require 'fauve/helpers'
metadata ADDED
@@ -0,0 +1,244 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fauve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Angel-Bradford
8
+ - Timothy Dang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sass
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 3.1.10
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 3.1.10
28
+ - !ruby/object:Gem::Dependency
29
+ name: rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '4.1'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '4.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: slim
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: railties
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: sprockets-rails
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '2.1'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '2.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: trollop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: bundler
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.3'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.3'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec-rails
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '3.1'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '3.1'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rake
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: pry
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: awesome_print
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: Fauve lets you manage your app's colour scheme
169
+ email:
170
+ - locusdelicti@gmail.com
171
+ - timothyqd@gmail.com
172
+ executables:
173
+ - fauve
174
+ extensions: []
175
+ extra_rdoc_files: []
176
+ files:
177
+ - ".gitignore"
178
+ - ".rspec"
179
+ - ".ruby-version"
180
+ - ".travis.yml"
181
+ - Gemfile
182
+ - LICENSE.txt
183
+ - README.md
184
+ - Rakefile
185
+ - bin/fauve
186
+ - fauve.gemspec
187
+ - lib/fauve.rb
188
+ - lib/fauve/cli.rb
189
+ - lib/fauve/colour_scheme.rb
190
+ - lib/fauve/config.rb
191
+ - lib/fauve/engine.rb
192
+ - lib/fauve/errors.rb
193
+ - lib/fauve/helpers.rb
194
+ - lib/fauve/railtie.rb
195
+ - lib/fauve/scheme/colour.rb
196
+ - lib/fauve/scheme/colour_map.rb
197
+ - lib/fauve/scheme/reference.rb
198
+ - lib/fauve/scheme/section.rb
199
+ - lib/fauve/version.rb
200
+ - spec/fixtures/fauve.yml
201
+ - spec/lib/fauve/colour_scheme_spec.rb
202
+ - spec/lib/fauve/config_spec.rb
203
+ - spec/lib/fauve/engine_spec.rb
204
+ - spec/lib/fauve/helpers_spec.rb
205
+ - spec/lib/fauve/railtie_spec.rb
206
+ - spec/lib/fauve/scheme/colour_spec.rb
207
+ - spec/lib/fauve/scheme/reference_spec.rb
208
+ - spec/lib/fauve/scheme/section_spec.rb
209
+ - spec/spec_helper.rb
210
+ homepage: ''
211
+ licenses:
212
+ - MIT
213
+ metadata: {}
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '2'
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 2.2.2
231
+ signing_key:
232
+ specification_version: 4
233
+ summary: Fauve lets you manage your app's colour scheme
234
+ test_files:
235
+ - spec/fixtures/fauve.yml
236
+ - spec/lib/fauve/colour_scheme_spec.rb
237
+ - spec/lib/fauve/config_spec.rb
238
+ - spec/lib/fauve/engine_spec.rb
239
+ - spec/lib/fauve/helpers_spec.rb
240
+ - spec/lib/fauve/railtie_spec.rb
241
+ - spec/lib/fauve/scheme/colour_spec.rb
242
+ - spec/lib/fauve/scheme/reference_spec.rb
243
+ - spec/lib/fauve/scheme/section_spec.rb
244
+ - spec/spec_helper.rb