Last active
August 29, 2015 14:15
-
-
Save tyronewilson/e21b925c5e8523fb73a3 to your computer and use it in GitHub Desktop.
haml helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
lib = File.expand_path('../lib', __FILE__) | |
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
require 'bs_helpers/version' | |
Gem::Specification.new do |spec| | |
spec.name = "bs_helpers" | |
spec.version = BsHelpers::VERSION | |
spec.authors = ["Tyrone Wilson"] | |
spec.email = ["[email protected]"] | |
spec.summary = %q{BsHelpers is a gem which provide bootstrap components in a helper format} | |
spec.description = %q{I could never remember how to use the various tags etc for bootstrap. I also found it difficult to write responsive templates all the time remembering | |
to set the various, col classes on my divs. I found it easier to have helpers which provided simple defaults which I could override when I needed to.} | |
spec.homepage = "" | |
spec.license = "MIT" | |
spec.files = `git ls-files -z`.split("\x0") | |
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | |
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | |
spec.require_paths = ["lib"] | |
spec.add_development_dependency "bundler", "~> 1.7" | |
spec.add_development_dependency "rake", "~> 10.0" | |
spec.add_runtime_dependency "railties" | |
spec.add_dependency "haml" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bs_helpers/version" | |
require "haml" | |
require "bs_helpers/railtie" if defined?(Rails) | |
module BsHelpers | |
include Haml::Helpers | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started GET "/" for 127.0.0.1 at 2015-02-17 11:49:41 +0200 | |
Processing by HomeController#index as HTML | |
Rendered home/index.html.erb within layouts/application (2.2ms) | |
Completed 500 Internal Server Error in 12ms | |
ActionView::Template::Error (undefined method `capture_position=' for nil:NilClass): | |
1: <h1>Home#index</h1> | |
2: <p>Find me in app/views/home/index.html.erb</p> | |
3: | |
4: <%= row %> | |
app/views/home/index.html.erb:4:in `_app_views_home_index_html_erb__3877064646291024799_69955829171420' | |
Rendered /home/tyrone/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (0.8ms) | |
Rendered /home/tyrone/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms) | |
Rendered /home/tyrone/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (7.9ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BsHelpers | |
module GridHelper | |
def row(tag: :div, **options, &block) | |
capture_haml do | |
haml_tag tag, class: "row #{options.fetch(:class, '')}" do | |
yield | |
end | |
end | |
end | |
def col(tag: :div,sm: 12, md: sm/2, lg: md, xs: sm, **options, &block) | |
cls = "col-md-#{md} col-sm-#{sm} col-lg-#{lg} #{options.fetch(:class, '')}" | |
capture_haml do | |
haml_tag tag, class: cls, **options do | |
yield | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#plug the helpers into rails with Railties | |
require 'bs_helpers/grid_helper' | |
module BsHelpers | |
class Railtie < Rails::Railtie | |
initializer "bs_helpers" do | |
ActionView::Base.send :include, Haml::Helpers | |
ActionView::Base.send :include, GridHelper | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment