grid_helper 0.0.0

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: 453d5da6a9386d5487df1b715bf49c5fae80f037
4
+ data.tar.gz: aa09e10b48a188c5b7375875a6ab4f807f05070b
5
+ SHA512:
6
+ metadata.gz: 057c0d53862bcf828fc8166b7bdfe484a4e97259a6bab197d087b31bfd5c507ef36f0a0898f92f672e76be49064ef0e0e02c8c24a381cb5c0e688a2a531f44d3
7
+ data.tar.gz: b2e39dfdff389219d931c8c770126563e881c35743b927bbb85404351f45d257c65108a31e81395d1e450a0438b9f65930cf046d6e3a093f87e4e891a2c1b15a
@@ -0,0 +1,3 @@
1
+ Gemfile
2
+ Gemfile.lock
3
+ Guardfile
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/grid/version', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'grid_helper'
7
+ s.version = Grid::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = "Jacob Evan Shreve"
10
+ s.email = %w(jacob@shreve.ly)
11
+ s.summary = 'A dsl for grid-system-based markup'
12
+ s.description = 'Grid helper creates helper methods to generate nice erb markup with nice html output.'
13
+ s.homepage = 'https://github.com/shreve/grid_helper'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.require_path = 'lib'
18
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'grid/builder'
2
+ require_relative 'grid/config'
3
+ require_relative 'grid/dsl'
4
+
5
+ if defined? Rails
6
+ require_relative 'grid/railtie'
7
+ end
8
+
9
+ module Grid
10
+ def self.config
11
+ @@config ||= Grid::Config.new
12
+ end
13
+
14
+ def self.configure(&block)
15
+ config
16
+ block.call(@@config)
17
+ end
18
+
19
+ def self.build_class(options)
20
+ klass = ""
21
+ [:large, :medium, :small, :xsmall].each do |size|
22
+ klass << " #{config.class_names[config.grid_system][size]}#{options[size]}" if config.class_names[config.grid_system][size]
23
+ end
24
+ klass << options[:class] if options[:class]
25
+ klass.strip
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Grid
2
+ module Builder
3
+
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ module Grid
2
+ class Config
3
+ attr_accessor :data
4
+
5
+ def initialize(options = {})
6
+ self.data = {
7
+ grid_system: :foundation,
8
+ class_names: {
9
+ foundation: {
10
+ large: 'large-',
11
+ medium: 'medium-',
12
+ small: 'small-'
13
+ },
14
+
15
+ bootstrap: {
16
+ large: 'col-lg-',
17
+ medium: 'col-md-',
18
+ small: 'col-sm-',
19
+ xsmall: 'col-xs-'
20
+ }
21
+ }
22
+ }
23
+ merge(options)
24
+ end
25
+
26
+ def method_missing(method, *args, &block)
27
+ if method.to_s.include?('=')
28
+ self.data[method.to_s.sub('=','').to_sym] = args.first
29
+ elsif data.has_key?(method)
30
+ data[method]
31
+ end
32
+ end
33
+
34
+ private
35
+ def merge(options = {})
36
+ if data.respond_to? :deep_merge!
37
+ self.data.deep_merge! options
38
+ else
39
+ self.data.merge! options
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ module Grid
2
+ module DSL
3
+ def column(content=nil, options={}, &block)
4
+ klass = GridHelper.build_class(options)
5
+ klass << "columns"
6
+ content_tag(
7
+ (options[:tag] || :div),
8
+ (content || options[:content] || capture("".html_safe, &block)),
9
+ class: klass)
10
+ end
11
+
12
+ def row(options={}, &block)
13
+ klass = "row"
14
+ klass << GridHelper.build_class(options)
15
+ content_tag(:div, capture("".html_safe, &block), class: klass)
16
+ end
17
+
18
+ {
19
+ one: 1,
20
+ two: 2,
21
+ three: 3,
22
+ four: 4,
23
+ five: 5,
24
+ six: 6,
25
+ seven: 7,
26
+ eight: 8,
27
+ nine: 9,
28
+ ten: 10,
29
+ eleven: 11,
30
+ twelve: 12
31
+ }.each do |w,n|
32
+ method_name = "#{n}_columns"
33
+ method_name.sub('s','') if n == 1
34
+ define_method(method_name) do |content=nil, options={}, &block|
35
+ options = Hash.new(n).merge(options)
36
+ column(content, options, &block)
37
+ end
38
+ alias_method "#{w}_block".to_sym, method_name
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ require 'grid/dsl'
2
+
3
+ module Grid
4
+ class Railtie < Rails::Railtie
5
+ initializer "grid.dsl" do
6
+ ActionView::Base.send :include, Grid::DSL
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Grid
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
+ end
9
+ end
data/license ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Jacob Evan Shreve
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Grid Helper
2
+
3
+ dsl for css grids, just because
4
+
5
+ grid helper can be used in erb templates.
6
+
7
+ ```
8
+ <%= row class: 'collapse field' do %>
9
+ <%= three_block f.label :name, class: 'prefix' %>
10
+ <%= nine_block f.textfield :name %>
11
+ <% end %>
12
+ ```
13
+
14
+ this renders
15
+
16
+ ```
17
+ <div class="row collapse field">
18
+ <div class="large-3 small-3 columns">
19
+ <label class="prefix" for="user_name">name</label>
20
+ </div>
21
+ <div class="large-9 small-9 columns">
22
+ <input type="text" id="user_name" name="user[name]" />
23
+ </div>
24
+ </div>
25
+ ```
26
+
27
+ grid helper can also be used in helpers by using a block parameter
28
+
29
+ ```
30
+ row class: 'collapse field' do |o|
31
+ o << three_block(f.label :name, class: 'prefix')
32
+ o << nine_block(f.textfield :name)
33
+ end
34
+ ```
35
+
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe GridHelper::Config do
4
+ before do
5
+ @config = GridHelper::Config.new
6
+ end
7
+
8
+ it "can be passed initialization options" do
9
+ config = GridHelper::Config.new({ option: :value })
10
+ config.option.must_equal :value
11
+ end
12
+
13
+ it "allows method access to data" do
14
+ @config.option = :value
15
+ @config.option.must_equal @config.data[:option]
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe GridHelper do
4
+
5
+ describe "configuration" do
6
+ it "allows method access to it's configuration" do
7
+ GridHelper.config.must_be_instance_of GridHelper::Config
8
+ end
9
+
10
+ it "keeps configuration set in a block" do
11
+ GridHelper.configure do |config|
12
+ config.custom_option = :a_value
13
+ end
14
+ GridHelper.config.custom_option.must_equal :a_value
15
+ end
16
+ end
17
+
18
+ describe "class builder" do
19
+ it "properly responds to size" do
20
+ options = {
21
+ small: 12,
22
+ medium: 8,
23
+ large: 2
24
+ }
25
+ GridHelper.config.grid_system = :foundation
26
+ GridHelper.build_class(options).must_equal "large-2 medium-8 small-12"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+
5
+ require_relative '../lib/grid_helper'
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grid_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Evan Shreve
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Grid helper creates helper methods to generate nice erb markup with nice
14
+ html output.
15
+ email:
16
+ - jacob@shreve.ly
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - grid_helper.gemspec
23
+ - lib/grid.rb
24
+ - lib/grid/builder.rb
25
+ - lib/grid/config.rb
26
+ - lib/grid/dsl.rb
27
+ - lib/grid/railtie.rb
28
+ - lib/grid/version.rb
29
+ - license
30
+ - readme.md
31
+ - spec/grid_helper/config_spec.rb
32
+ - spec/grid_helper_spec.rb
33
+ - spec/spec_helper.rb
34
+ homepage: https://github.com/shreve/grid_helper
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.2.0
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: A dsl for grid-system-based markup
58
+ test_files: []