kube-rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,38 @@
1
1
  # Kube for Rails 3.1 Asset Pipeline
2
+ [Kube](http://imperavi.com/kube/) is a minimal CSS-framework for developers. This projects integrates it for Rails 3.1 Asset Pipeline.
2
3
 
3
4
  [![Build Status](https://secure.travis-ci.org/mmozuras/kube-rails.png)](http://travis-ci.org/mmozuras/kube-rails)
5
+
6
+ ## Installing Gem
7
+
8
+ Include the [Kube Rails gem](http://rubygems.org/gems/kube-rails) in Gemfile to install it from [RubyGems.org](http://rubygems.org);
9
+
10
+ ```ruby
11
+ gem "kube-rails"
12
+ ```
13
+
14
+ Then run ```bundle install``` from the command line.
15
+
16
+ ## Using Generators
17
+
18
+ #### Install
19
+
20
+ Installs Kube to Asset Pipeline.
21
+
22
+ Usage:
23
+
24
+ rails g kube:install
25
+
26
+ #### Themed
27
+
28
+ Generate Kube compatible scaffold views. Support for Haml and Slim is available.
29
+
30
+ Usage:
31
+
32
+ rails g kube:themed [RESOURCE]
33
+
34
+ Example:
35
+
36
+ rails g scaffold Post title:string description:text
37
+ rake db:migrate
38
+ rails s kube:themed Posts
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ Bundler::GemHelper.install_tasks
4
4
 
5
5
  desc "Bundle the gem"
6
6
  task :bundle do
7
- sh('bundle install')
7
+ sh 'bundle install'
8
8
  sh 'gem build *.gemspec'
9
9
  sh 'gem install *.gem'
10
10
  sh 'rm *.gem'
@@ -0,0 +1,15 @@
1
+ <%%= form_for @<%= resource_name %>, :html => { :class => 'forms' } do |f| %>
2
+ <ul>
3
+ <%- columns.each do |column| -%>
4
+ <li>
5
+ <%%= f.label :<%= column.name %>, :class => 'bold' %>
6
+ <%%= f.<%= column.field_type %> :<%= column.name %> %>
7
+ </li>
8
+ <%- end -%>
9
+
10
+ <li>
11
+ <%%= f.submit nil, :class => 'btn' %>
12
+ <%%= link_to 'Cancel', <%= controller_routing_path %>_path, :class => 'btn' %>
13
+ <li>
14
+ </ul>
15
+ <%% end %>
@@ -0,0 +1,11 @@
1
+ = form_for @<%= resource_name %>, :html => { :class => 'forms' } do |f|
2
+ %ul
3
+ <%- columns.each do |column| -%>
4
+ %li
5
+ = f.label :<%= column.name %>, :class => 'bold'
6
+ = f.<%= column.field_type %> :<%= column.name %>
7
+ <%- end -%>
8
+
9
+ %li
10
+ = f.submit nil, :class => 'btn'
11
+ = link_to 'Cancel', <%= controller_routing_path %>_path, :class => 'btn'
@@ -0,0 +1,11 @@
1
+ = form_for @<%= resource_name %>, :html => { :class => 'forms' } do |f|
2
+ ul
3
+ <%- columns.each do |column| -%>
4
+ li
5
+ = f.label :<%= column.name %>, :class => 'bold'
6
+ = f.<%= column.field_type %> :<%= column.name %>
7
+ <%- end -%>
8
+
9
+ li
10
+ = f.submit nil, :class => 'btn'
11
+ = link_to 'Cancel', <%= controller_routing_path %>_path, :class => 'btn'
@@ -0,0 +1,2 @@
1
+ <h1><%%= "Edit #{<%= model_class %>.model_name.human}" %></h1>
2
+ <%%= render :partial => 'form' %>
@@ -0,0 +1,2 @@
1
+ %h1= "Edit #{<%= model_class %>.model_name.human}"
2
+ = render :partial => "form"
@@ -0,0 +1,2 @@
1
+ h1= "Edit #{<%= model_class %>.model_name.human}"
2
+ = render :partial => "form"
@@ -0,0 +1,35 @@
1
+ <%%- model_class = <%= model_class %> -%>
2
+ <h1><%%= model_class.model_name.human.pluralize %></h1>
3
+
4
+ <table class="striped">
5
+ <thead class="thead-black">
6
+ <tr>
7
+ <th><%%= model_class.human_attribute_name(:id) %></th>
8
+ <%- columns.each do |column| -%>
9
+ <th><%%= model_class.human_attribute_name(:<%= column.name %>) %></th>
10
+ <%- end -%>
11
+ <th><%%= model_class.human_attribute_name(:created_at) %></th>
12
+ <th>Actions</th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <%% @<%= plural_resource_name %>.each do |<%= resource_name %>| %>
17
+ <tr>
18
+ <td><%%= link_to <%= resource_name %>.id, <%= singular_controller_routing_path %>_path(<%= resource_name %>) %></td>
19
+ <%- columns.each do |column| -%>
20
+ <td><%%= <%= resource_name %>.<%= column.name %> %></td>
21
+ <%- end -%>
22
+ <td><%%=l <%= resource_name %>.created_at %></td>
23
+ <td>
24
+ <%%= link_to 'Edit', edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-small' %>
25
+ <%%= link_to 'Destroy', <%= singular_controller_routing_path %>_path(<%= resource_name %>),
26
+ :method => :delete,
27
+ :data => { :confirm => 'Are you sure?' },
28
+ :class => 'btn btn-small' %>
29
+ </td>
30
+ </tr>
31
+ <%% end %>
32
+ </tbody>
33
+ </table>
34
+
35
+ <%%= link_to 'New', new_<%= singular_controller_routing_path %>_path, :class => 'btn' %>
@@ -0,0 +1,24 @@
1
+ - model_class = <%= model_class %>
2
+ %h1= model_class.model_name.human.pluralize
3
+ %table.striped
4
+ %thead.thead-black
5
+ %tr
6
+ %th= model_class.human_attribute_name(:id)
7
+ <%- columns.each do |column| -%>
8
+ %th= model_class.human_attribute_name(:<%= column.name %>)
9
+ <%- end -%>
10
+ %th= model_class.human_attribute_name(:created_at)
11
+ %th Actions
12
+ %tbody
13
+ - @<%= plural_resource_name %>.each do |<%= resource_name %>|
14
+ %tr
15
+ %td= link_to <%= resource_name %>.id, <%= singular_controller_routing_path %>_path(<%= resource_name %>)
16
+ <%- columns.each do |column| -%>
17
+ %td= <%= resource_name %>.<%= column.name %>
18
+ <%- end -%>
19
+ %td=l <%= resource_name %>.created_at
20
+ %td
21
+ = link_to 'Edit', edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-small'
22
+ = link_to 'Destroy', <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-small'
23
+
24
+ = link_to 'New', new_<%= singular_controller_routing_path %>_path, :class => 'btn'
@@ -0,0 +1,24 @@
1
+ - model_class = <%= model_class %>
2
+ h1= model_class.model_name.human.pluralize
3
+ table.striped
4
+ thead.thead-black
5
+ tr
6
+ th= model_class.human_attribute_name(:id)
7
+ <%- columns.each do |column| -%>
8
+ th= model_class.human_attribute_name(:<%= column.name %>)
9
+ <%- end -%>
10
+ th= model_class.human_attribute_name(:created_at)
11
+ th Actions
12
+ tbody
13
+ - @<%= plural_resource_name %>.each do |<%= resource_name %>|
14
+ tr
15
+ td= link_to <%= resource_name %>.id, <%= singular_controller_routing_path %>_path(<%= resource_name %>)
16
+ <%- columns.each do |column| -%>
17
+ td= <%= resource_name %>.<%= column.name %>
18
+ <%- end -%>
19
+ td=l <%= resource_name %>.created_at
20
+ td
21
+ = link_to 'Edit', edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-small'
22
+ = link_to 'Destroy', <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-small'
23
+
24
+ = link_to 'New', new_<%= singular_controller_routing_path %>_path, :class => 'btn'
@@ -0,0 +1,2 @@
1
+ <h1><%%= "New #{<%= model_class %>.model_name.human}" %></h1>
2
+ <%%= render :partial => 'form' %>
@@ -0,0 +1,2 @@
1
+ %h1= "New #{<%= model_class %>.model_name.human}"
2
+ = render :partial => "form"
@@ -0,0 +1,2 @@
1
+ h1= "New #{<%= model_class %>.model_name.human}"
2
+ = render :partial => "form"
@@ -0,0 +1,18 @@
1
+ <%%- model_class = <%= model_class %> -%>
2
+ <h1><%%= model_class.model_name.human %></h1>
3
+
4
+ <dl>
5
+ <%- columns.each do |column| -%>
6
+ <dt class="bold"><%%= model_class.human_attribute_name(:<%= column.name %>) %>:</dt>
7
+ <dd><%%= @<%= resource_name %>.<%= column.name %> %></dd>
8
+ <%- end -%>
9
+ </dl>
10
+
11
+ <div>
12
+ <%%= link_to 'Back', <%= controller_routing_path %>_path, :class => 'btn' %>
13
+ <%%= link_to 'Edit', edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn' %>
14
+ <%%= link_to 'Destroy', <%= singular_controller_routing_path %>_path(@<%= resource_name %>),
15
+ :method => 'delete',
16
+ :data => { :confirm => 'Are you sure?' },
17
+ :class => 'btn' %>
18
+ </div>
@@ -0,0 +1,13 @@
1
+ - model_class = <%= model_class %>
2
+ %h1= model_class.model_name.human
3
+
4
+ %dl
5
+ <%- columns.each do |column| -%>
6
+ %dt.bold= model_class.human_attribute_name(:<%= column.name %>) + ':'
7
+ %dd= @<%= resource_name %>.<%= column.name %>
8
+ <%- end -%>
9
+
10
+ %div
11
+ = link_to 'Back', <%= controller_routing_path %>_path, :class => 'btn'
12
+ = link_to 'Edit', edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn'
13
+ = link_to 'Destroy', <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :method => "delete", :data => { :confirm => 'Are you sure?' }, :class => 'btn'
@@ -0,0 +1,13 @@
1
+ - model_class = <%= model_class %>
2
+ h1= model_class.model_name.human
3
+
4
+ dl
5
+ <%- columns.each do |column| -%>
6
+ dt.bold= model_class.human_attribute_name(:<%= column.name %>) + ':'
7
+ dd= @<%= resource_name %>.<%= column.name %>
8
+ <%- end -%>
9
+
10
+ div
11
+ = link_to 'Back', <%= controller_routing_path %>_path, :class => 'btn'
12
+ = link_to 'Edit', edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn'
13
+ = link_to 'Destroy', <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :method => "delete", :data => { :confirm => 'Are you sure?' }, :class => 'btn'
@@ -0,0 +1,96 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/generated_attribute'
3
+
4
+ module Kube
5
+ module Generators
6
+ class ThemedGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ argument :controller_path, :type => :string
9
+ argument :model_name, :type => :string, :required => false
10
+ argument :layout, :type => :string, :default => "application",
11
+ :banner => "Specify application layout"
12
+
13
+ def initialize(args, *options)
14
+ super(args, *options)
15
+ initialize_views_variables
16
+ end
17
+
18
+ def copy_views
19
+ generate_views
20
+ end
21
+
22
+ protected
23
+
24
+ def initialize_views_variables
25
+ @base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
26
+ @controller_routing_path = @controller_file_path.gsub(/\//, '_')
27
+ @model_name = @controller_class_nesting + "::#{@base_name.singularize.camelize}" unless @model_name
28
+ @model_name = @model_name.camelize
29
+ end
30
+
31
+ def controller_routing_path
32
+ @controller_routing_path
33
+ end
34
+
35
+ def singular_controller_routing_path
36
+ @controller_routing_path.singularize
37
+ end
38
+
39
+ def model_class
40
+ resource_name.classify
41
+ end
42
+
43
+ def resource_name
44
+ @model_name.demodulize.underscore
45
+ end
46
+
47
+ def plural_resource_name
48
+ resource_name.pluralize
49
+ end
50
+
51
+ def columns
52
+ begin
53
+ excluded_column_names = %w[id created_at updated_at]
54
+ begin
55
+ @model_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
56
+ rescue ActiveRecord::StatementInvalid => e
57
+ say e.message, :red
58
+ exit
59
+ end
60
+ rescue NoMethodError
61
+ @model_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
62
+ end
63
+ end
64
+
65
+ def extract_modules(name)
66
+ modules = name.include?('/') ? name.split('/') : name.split('::')
67
+ name = modules.pop
68
+ path = modules.map { |m| m.underscore }
69
+ file_path = (path + [name.underscore]).join('/')
70
+ nesting = modules.map { |m| m.camelize }.join('::')
71
+ [name, path, file_path, nesting, modules.size]
72
+ end
73
+
74
+ def generate_views
75
+ views = {
76
+ "index.html.#{ext}" => File.join('app/views', @controller_file_path, "index.html.#{ext}"),
77
+ "new.html.#{ext}" => File.join('app/views', @controller_file_path, "new.html.#{ext}"),
78
+ "edit.html.#{ext}" => File.join('app/views', @controller_file_path, "edit.html.#{ext}"),
79
+ "_form.html.#{ext}" => File.join('app/views', @controller_file_path, "_form.html.#{ext}"),
80
+ "show.html.#{ext}" => File.join('app/views', @controller_file_path, "show.html.#{ext}")}
81
+ selected_views = views
82
+ options.engine == generate_templates(selected_views)
83
+ end
84
+
85
+ def generate_templates(views)
86
+ views.each do |template_name, output_path|
87
+ template template_name, output_path
88
+ end
89
+ end
90
+
91
+ def ext
92
+ ::Rails.application.config.generators.options[:rails][:template_engine] || :erb
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,5 +1,5 @@
1
1
  module Kube
2
2
  module Rails
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kube-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-14 00:00:00.000000000 Z
12
+ date: 2012-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -101,6 +101,22 @@ files:
101
101
  - lib/generators/kube/install/install_generator.rb
102
102
  - lib/generators/kube/install/templates/application.css
103
103
  - lib/generators/kube/install/templates/kube.less
104
+ - lib/generators/kube/themed/templates/_form.html.erb
105
+ - lib/generators/kube/themed/templates/_form.html.haml
106
+ - lib/generators/kube/themed/templates/_form.html.slim
107
+ - lib/generators/kube/themed/templates/edit.html.erb
108
+ - lib/generators/kube/themed/templates/edit.html.haml
109
+ - lib/generators/kube/themed/templates/edit.html.slim
110
+ - lib/generators/kube/themed/templates/index.html.erb
111
+ - lib/generators/kube/themed/templates/index.html.haml
112
+ - lib/generators/kube/themed/templates/index.html.slim
113
+ - lib/generators/kube/themed/templates/new.html.erb
114
+ - lib/generators/kube/themed/templates/new.html.haml
115
+ - lib/generators/kube/themed/templates/new.html.slim
116
+ - lib/generators/kube/themed/templates/show.html.erb
117
+ - lib/generators/kube/themed/templates/show.html.haml
118
+ - lib/generators/kube/themed/templates/show.html.slim
119
+ - lib/generators/kube/themed/themed_generator.rb
104
120
  - lib/kube/rails/engine.rb
105
121
  - lib/kube/rails/kube.rb
106
122
  - lib/kube/rails/version.rb
@@ -139,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
155
  version: '0'
140
156
  requirements: []
141
157
  rubyforge_project: kube-rails
142
- rubygems_version: 1.8.24
158
+ rubygems_version: 1.8.23
143
159
  signing_key:
144
160
  specification_version: 3
145
161
  summary: Kube for Rails 3.1 Asset Pipeline