0.0
No commit activity in last 3 years
No release in over 3 years
Useful concept for views, css and js organization
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

SmartBlocks

Generators and helpers written by verybigman for convenient views, css and js organization.

Installation

Add this line to your application's Gemfile:

gem 'smart_blocks'

And then execute:

$ bundle

Or install it yourself as:

$ gem install smart_blocks

Then add to css manifest (application.css):

*= require_tree ./_blocks

And to js manifest (application.js):

//= require_tree ./_blocks

After that restart your rails server, it's important (if you are on Rails).

Usage

Create block

$ rails g smart_blocks:block header_main
  # create -> app/views/_blocks/headers/_header_main.html.haml
  # create -> app/assets/stylesheets/_blocks/headers/header_main.css.sass
  # create -> app/assets/javascripts/_blocks/headers/header_main.js.coffee

Create element (parts of block)

$ rails g smart_blocks:element header_logged_in
  # create -> app/views/_blocks/headers/elements/_header_logged_in.html.haml
  # create -> app/assets/stylesheets/_blocks/headers/elements/header_logged_in.css.sass
  # create -> app/assets/javascripts/_blocks/headers/elements/header_logged_in.js.coffee

Views

(layout/application.html.haml):

= block 'header_main'

Show in this block elements depends on logged in user or not

- if current_user
  = element 'header_logged_in'
- else
  = element 'header_guest'

Also you can pass variables:

= block 'menu_main', some_var: value
= element 'button_submit', other_var: value

Flags

You can generate slim view instead of haml. To do that just pass --slim:

rails g smart_blocks:block   navbar --slim
rails g smart_blocks:element navbar_link --slim

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request