Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding slim and kaminari support #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you want to use another theme, instead of the default, you can use the `--the

rails g web_app_theme:theme admin --theme="drastic-dark"

You can specify the template engine with `--engine=name` option, where name can be erb (default) or haml:
You can specify the template engine with `--engine=name` option, where name can be erb (default), haml or slim (requires haml2slim and hpricot):

rails g web_app_theme:theme --engine=haml # you must specify haml in your Gemfile

Expand Down Expand Up @@ -69,7 +69,7 @@ If the controller has a name different to the model used, specify the controller

rails g web_app_theme:themed admin/items post

If you use `will_paginate` for pagination use the `--will-paginate`:
If you use a pagination gem like `will_paginate` or `kaminari`, use the `--will-paginate` or `--kaminari`:

rails g web_app_theme:themed items post --will-paginate

Expand Down Expand Up @@ -156,4 +156,4 @@ Credits
-------

* Icons: FAMFAMFAM Silk icons <http://www.famfamfam.com/lab/icons/silk/>
* Buttons: Particletree - Rediscovering the Button Element <http://particletree.com/features/rediscovering-the-button-element/>
* Buttons: Particletree - Rediscovering the Button Element <http://particletree.com/features/rediscovering-the-button-element/>
18 changes: 18 additions & 0 deletions lib/generators/web_app_theme/theme/theme_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def copy_layout
template admin_layout_name, "app/views/layouts/#{layout_name.underscore}.html.erb"
when 'haml'
generate_haml_layout(admin_layout_name)
when 'slim'
generate_slim_layout(admin_layout_name)
end
end

Expand Down Expand Up @@ -57,5 +59,21 @@ def generate_haml_layout(admin_layout_name)
say "HAML is not installed, or it is not specified in your Gemfile."
exit
end

def generate_slim_layout(admin_layout_name)
require 'haml2slim'
Dir.mktmpdir('web-app-theme-slim') do |slim_root|
tmp_html_path = "#{slim_root}/#{admin_layout_name}"
tmp_haml_path = "#{slim_root}/#{admin_layout_name}.haml"
tmp_slim_path = "#{slim_root}/#{admin_layout_name}.slim"
template admin_layout_name, tmp_html_path, :verbose => false
`html2haml --erb --xhtml #{tmp_html_path} #{tmp_haml_path}`
`haml2slim #{tmp_haml_path} #{tmp_slim_path}`
copy_file tmp_slim_path, "app/views/layouts/#{layout_name.underscore}.html.slim"
end
rescue LoadError
say "haml2slim not installed, or it is not specified in your Gemfile."
exit
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<% if options.will_paginate %>
<%%= will_paginate @<%= plural_resource_name %> %>
<% end %>
<% if options.kaminari %>
<%%= paginate @<%= plural_resource_name %> %>
<% end %>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/generators/web_app_theme/themed/themed_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ThemedGenerator < Rails::Generators::Base
class_option :layout, :type => :string, :desc => 'Specify the layout name'
class_option :engine, :type => :string, :default => 'erb', :desc => 'Specify the template engine'
class_option :will_paginate, :type => :boolean, :default => false, :desc => 'Specify if you use will_paginate'
class_option :kaminari, :type => :boolean, :default => false, :desc => 'Specify if you use kaminari'
class_option :themed_type, :type => :string, :default => 'crud', :desc => 'Specify the themed type, crud or text. Default is crud'

def initialize(args, *options)
Expand Down