Generators and helpers written by verybigman for convenient views, css and js organization.
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).
$ 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
$ 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
(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
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request