grids 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ .sass-cache
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grids.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'pry'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vadim Rastyagaev
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
File without changes
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/grids.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/grids/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Vadim Rastyagaev"]
6
+ gem.email = ["abc@oktoberliner.ru"]
7
+ gem.description = %q{SASS helpers for grid systems management}
8
+ gem.summary = %q{SASS helpers for grid systems management}
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "grids"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Grids::VERSION
16
+
17
+ gem.add_dependency 'sass', '~> 3.2'
18
+ end
@@ -0,0 +1,58 @@
1
+ <%= context%>
2
+
3
+ $<%= name %>-atom-x: <%= atom_x %>;
4
+ $<%= name %>-atom-y: <%= atom_y %>;
5
+
6
+ $<%= name %>-gutter-x: <%= defined?(gutter_x) ? gutter_x : atom_x; %>;
7
+ $<%= name %>-gutter-y: <%= defined?(gutter_y) ? gutter_y : atom_y; %>;
8
+
9
+ $<%= name %>-module-width: <%= module_width %>;
10
+ <% if defined? module_height %>
11
+ $<%= name %>-module-height: <%= module_height %>;
12
+ <% end %>
13
+
14
+ $<%= name %>-modules-x-count: <%= modules_x_count %>;
15
+ <% if defined? modules_y_count %>
16
+ $<%= name %>-modules_y_count: <%= modules_x_count %>;
17
+ <% end %>
18
+
19
+ @function <%= name %>-x($t: 1) {
20
+ @return $<%= name %>-atom-x * $t;
21
+ }
22
+ @function <%= name %>-y($t: 1) {
23
+ @return $<%= name %>-atom-y * $t;
24
+ }
25
+
26
+ @function <%= name %>-gutter-x($t: 1) {
27
+ @return $<%= name %>-gutter-x * $t;
28
+ }
29
+ @function <%= name %>-gutter-y($t: 1) {
30
+ @return $<%= name %>-gutter-y * $t;
31
+ }
32
+
33
+ @function <%= name %>-modules-x($m) {
34
+ @return <%= name %>-x($<%= name %>-module-width * $m) + <%= name %>-gutter-x($m - 1);
35
+ }
36
+ <% if defined? module_height %>
37
+ @function <%= name %>-modules-y($m) {
38
+ @return <%= name %>-y($<%= name %>-module-height * $m) + <%= name %>-gutter-y($m - 1);
39
+ }
40
+ <% end %>
41
+
42
+ @function <%= name %>-modules-gap-x($m) {
43
+ @return <%= name %>-modules-x($m) + <%= name %>-gutter-x(1);
44
+ }
45
+ <% if defined? module_height %>
46
+ @function <%= name %>-modules-gap-y($m) {
47
+ @return <%= name %>-modules-y($m) + <%= name %>-gutter-y(1);
48
+ }
49
+ <% end %>
50
+
51
+ @function <%= name %>-full-page-width() {
52
+ @return <%= name %>-modules-x($<%= name %>-modules-x-count)
53
+ }
54
+ <% if defined? module_height and defined? modules_y_count %>
55
+ @function <%= name %>-full-page-height() {
56
+ @return <%= name %>-modules-y($<%= name %>-modules-y-count)
57
+ }
58
+ <% end %>
@@ -0,0 +1,52 @@
1
+ require 'erb'
2
+ require 'ostruct'
3
+
4
+ module Grids
5
+ class Binding < OpenStruct
6
+ def get_binding
7
+ binding()
8
+ end
9
+ end
10
+
11
+ class Importer < Sass::Importers::Filesystem
12
+ EXT_REGEX = /\.grid$/
13
+
14
+ private
15
+
16
+ def _find(dir, name, options)
17
+ return unless name =~ EXT_REGEX
18
+ Sass::Engine.new(generate_grid(name, options), options)
19
+ end
20
+
21
+ def grid_name(filename)
22
+ filename.split('/').last.split('.').first
23
+ end
24
+
25
+ def generate_grid(name, options)
26
+ grid_settings = grid_settings_map(name, options)
27
+ grid_settings[:name] = grid_name(name)
28
+ grid_settings[:context] = import_settings_template(name)
29
+
30
+ binding = Binding.new(grid_settings)
31
+
32
+ grid_template_path = File.join(File.expand_path('../', __FILE__), 'grid.scss.erb')
33
+ grid_template = ERB.new(File.read(grid_template_path))
34
+
35
+ grid_template.result(binding.get_binding)
36
+ end
37
+
38
+ def grid_settings_map(filename, options)
39
+ import_engine = Sass::Engine.new(import_settings_template(filename), options)
40
+ import_node = import_engine.to_tree.to_a.last
41
+ engine = import_node.imported_file
42
+ variables = engine.to_tree.to_a.select{|v| v.is_a? Sass::Tree::VariableNode }
43
+ Hash[variables.map{|v| [v.name.gsub('-', '_'), v.expr.to_sass]}]
44
+ end
45
+
46
+ def import_settings_template(filename)
47
+ settings_file_name = filename.gsub(EXT_REGEX, '')
48
+ import_template = "@import '#{settings_file_name}';"
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,3 @@
1
+ module Grids
2
+ VERSION = "1.1.0"
3
+ end
data/lib/grids.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'sass'
2
+ require 'grids/importer'
3
+ require "grids/version"
4
+
5
+ module Grids
6
+ Sass.load_paths << Importer.new('.')
7
+ end
@@ -0,0 +1,5 @@
1
+ @import 'display.grid';
2
+
3
+ body {
4
+ width: display-full-page-width();
5
+ }
@@ -0,0 +1,6 @@
1
+ $atom-x: 42px;
2
+ $atom-y: 21px;
3
+ $module-width: 1;
4
+ $module-height: 1;
5
+ $modules-x-count: 12;
6
+ $modules-y-count: 12;
@@ -0,0 +1,4 @@
1
+ $atom-x: 100% / 11;
2
+ $atom-y: 21px;
3
+ $module-width: 1;
4
+ $modules-x-count: 6;
data/spec/grid_spec.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "Grid named functions" do
4
+ let (:source) { "@import './spec/fixtures/display.grid';" }
5
+ let (:output) { Sass.compile(source, style: :compact) }
6
+
7
+ specify 'x' do
8
+ source << "body { width: display-x(2); }\n"
9
+ output.should == "body { width: 84px; }\n"
10
+ end
11
+
12
+ specify 'y' do
13
+ source << "body { height: display-y(2); }\n"
14
+ output.should == "body { height: 42px; }\n"
15
+ end
16
+
17
+ specify 'gutter-x' do
18
+ source << "body { margin-right: display-gutter-x(1); }\n"
19
+ output.should == "body { margin-right: 42px; }\n"
20
+ end
21
+
22
+ specify 'gutter-y' do
23
+ source << "body { margin-bottom: display-gutter-y(1); }\n"
24
+ output.should == "body { margin-bottom: 21px; }\n"
25
+ end
26
+
27
+ specify 'modules-x' do
28
+ source << "body { width: display-modules-x(2); }\n"
29
+ output.should == "body { width: 126px; }\n"
30
+ end
31
+
32
+ specify 'modules-y' do
33
+ source << "body { height: display-modules-y(2); }\n"
34
+ output.should == "body { height: 63px; }\n"
35
+ end
36
+
37
+ specify 'modules-gap-x' do
38
+ source << "body { width: display-modules-gap-x(2); }\n"
39
+ output.should == "body { width: 168px; }\n"
40
+ end
41
+
42
+ specify 'modules-gap-y' do
43
+ source << "body { height: display-modules-gap-y(2); }\n"
44
+ output.should == "body { height: 84px; }\n"
45
+ end
46
+
47
+ specify 'full-page-width' do
48
+ source << "body { width: display-full-page-width(); }\n"
49
+ output.should == "body { width: 966px; }\n"
50
+ end
51
+
52
+ specify 'full-page-height' do
53
+ source << "body { height: display-full-page-height(); }\n"
54
+ output.should == "body { height: 483px; }\n"
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe "Importer" do
4
+ it "should add an importer to Sass.load_paths" do
5
+ Sass.load_paths.last.class.should == Grids::Importer
6
+ end
7
+
8
+ it "should be able to import grid settings" do
9
+ source = "@import './spec/fixtures/display.grid'"
10
+ expect { Sass.compile(source) }.to_not raise_error(Sass::SyntaxError)
11
+ end
12
+
13
+ it "should be able to make a grid from imported settings" do
14
+ source = "
15
+ @import './spec/fixtures/display.grid';
16
+ body { width: display-full-page-width(); }
17
+ "
18
+ Sass.compile(source).should == "body {\n width: 966px; }\n"
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Grid' do
4
+ it 'should be able to make two different grid helpers' do
5
+ source = "
6
+ @import './spec/fixtures/display.grid';
7
+ @import './spec/fixtures/mobile.grid';
8
+ body.display { width: display-full-page-width(); }
9
+ body.mobile { width: mobile-full-page-width(); }
10
+ "
11
+
12
+ Sass.compile(source).gsub(/\s/, '').should == "
13
+ body.display { width: 966px; }
14
+ body.mobile { width: 100%; }
15
+ ".gsub(/\s/, '')
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+ require 'tempfile'
3
+
4
+ describe "Grid settings" do
5
+ # specify "required atom-x"
6
+ # specify "optional atom-y"
7
+
8
+ # specify "required module-width"
9
+ # specify "optional module-height"
10
+
11
+ # specify "required modules-x-count"
12
+ # specify "optional modules-y-count"
13
+
14
+ # specify "optional gutter-x"
15
+ # specify "optional gutter-y"
16
+ end
@@ -0,0 +1,3 @@
1
+ require 'pry'
2
+ require 'sass'
3
+ require 'grids'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grids
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vadim Rastyagaev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sass
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ description: SASS helpers for grid systems management
31
+ email:
32
+ - abc@oktoberliner.ru
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - grids.gemspec
43
+ - lib/grids.rb
44
+ - lib/grids/grid.scss.erb
45
+ - lib/grids/importer.rb
46
+ - lib/grids/version.rb
47
+ - spec/fixtures/application.scss
48
+ - spec/fixtures/display.scss
49
+ - spec/fixtures/mobile.scss
50
+ - spec/grid_spec.rb
51
+ - spec/importer_spec.rb
52
+ - spec/multiple_grids_spec.rb
53
+ - spec/settings_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage:
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.23
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: SASS helpers for grid systems management
79
+ test_files:
80
+ - spec/fixtures/application.scss
81
+ - spec/fixtures/display.scss
82
+ - spec/fixtures/mobile.scss
83
+ - spec/grid_spec.rb
84
+ - spec/importer_spec.rb
85
+ - spec/multiple_grids_spec.rb
86
+ - spec/settings_spec.rb
87
+ - spec/spec_helper.rb