itium-theme 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>itium-theme</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ <nature>org.radrails.rails.core.railsnature</nature>
11
+ <nature>com.aptana.ruby.core.rubynature</nature>
12
+ </natures>
13
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itium-theme.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Hamilton Oliveira
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Itium::Theme
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'itium-theme'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install itium-theme
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'itium-theme/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "itium-theme"
8
+ gem.version = Itium::Theme::VERSION
9
+ gem.authors = ["Hamilton Oliveira"]
10
+ gem.email = ["hamilton.oliveira@itium.com.br"]
11
+ gem.description = %q{View generator for rails projects using simple_form and bootstrap}
12
+ gem.summary = %q{View generator for rails projects using simple_form and bootstrap}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,7 @@
1
+ <h1><%%= t("itium-theme.edit", :default => "Edit")%> <%%= t("activerecord.models.<%= model_name %>", :default => "<%= model_name%>")%></h1>
2
+
3
+ <%%= link_to t("itium-theme.back", :default => "Back"), <%= controller_routing_path %>_path %>
4
+ <%%= link_to t("itium-theme.show", :default => "Show"), @<%= resource_name %> %>
5
+
6
+ <%%= render 'form' %>
7
+
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%=resource_name%>) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <% columns.each do |column| %>
5
+
6
+ <%%= f.input :<%= column.name %> %>
7
+
8
+ <%- end -%>
9
+
10
+ <div class="form-actions">
11
+ <%%= f.button :submit, t("itium-theme.save", :default => "Save") %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,36 @@
1
+ <h1><%%= t("itium-theme.list", :default => "List of") %> <%%= t("activerecord.models.<%= model_name %>", :default => "<%= plural_model_name%>") %></h1>
2
+ <br>
3
+
4
+ <%%= render :partial => "search", :locals => {:f => f} %>
5
+
6
+ <table class="table table-bordered table-striped">
7
+ <tr>
8
+ <th>ID</th>
9
+ <% unless columns.empty? -%>
10
+ <th> <%%= t("activerecord.attributes.<%= singular_controller_routing_path %>.<%= columns.first.name %>", :default => "<%= columns.first.name.capitalize %>") %> </th>
11
+ <% end -%>
12
+ <th></th>
13
+ <th></th>
14
+ <th></th>
15
+ </tr>
16
+
17
+ <%% @<%= plural_resource_name %>.each do |<%= resource_name %>| -%>
18
+ <tr>
19
+ <td><%%= <%= resource_name %>.id %></td>
20
+ <% unless columns.empty? -%>
21
+ <td> <%%= link_to <%= resource_name %>.<%= columns.first.name %>, <%= singular_controller_routing_path %>_path(<%= resource_name %>) %> </td>
22
+ <% end -%>
23
+ <td><%%= link_to raw("<i class='icon-folder-open'></i>"), <%= resource_name %>, :class => "btn btn-mini", :title => "#{t("itium-theme.show", :default => "Show")}" %></td>
24
+ <td><%%= link_to raw("<i class='icon-pencil'></i>"), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => "btn btn-mini", :title => "#{t("itium-theme.edit", :default => "Show")}" %></td>
25
+ <td><%%= link_to raw("<i class='icon-remove-sign'></i>"), <%= resource_name %>, :confirm => "#{t("itium-theme.confirm", :default => "Are you sure?")}", :method => :delete, :class => "btn btn-mini", :title => "#{t("itium-theme.delete", :default => "Delete")}" %></td>
26
+ </tr>
27
+ <% % end %>
28
+ </table>
29
+
30
+ <br />
31
+
32
+ <% if options.will_paginate %>
33
+ <%%= will_paginate @<%= plural_resource_name %> %>
34
+ <% end %>
35
+
36
+ <%= link_to raw("<i class='icon-file'></i>Adicionar"), new_<%= singular_controller_routing_path %>_path, :class => "btn", :title => "#{t("itium-theme.new", :default => "Novo")}" %>
@@ -0,0 +1,6 @@
1
+ <h1><%%= t("itium-theme.new", :default => "New")%> <%%= t("activerecord.models.<%= model_name %>", :default => "<%= model_name%>")%></h1>
2
+
3
+ <%%= link_to t("itium-theme.back", :default => "Back"), <%= controller_routing_path %>_path %>
4
+
5
+ <%%= render 'form' %>
6
+
@@ -0,0 +1,3 @@
1
+ <%%= form_tag <%= controller_routing_path %>_path, :method => :get, :class => "well form-inline" do -%>
2
+ <button type="submit" class="btn"><i class="icon-search"></i></button>
3
+ <%% end -%>
@@ -0,0 +1,11 @@
1
+ <%%= link_to t("itium-theme.back", :default => "Back"), <%= controller_routing_path %>_path %>
2
+ <%%= link_to t("itium-theme.edit", :default => "Edit"), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>) %>
3
+
4
+ <% columns.each do |column| %>
5
+ <p>
6
+ <b><%%= t("activerecord.attributes.<%= singular_controller_routing_path %>.<%= column.name %>", :default => "<%= column.name.humanize %>") %>:</b>
7
+ <%%= @<%= resource_name %>.<%= column.name %> %>
8
+ </p>
9
+ <%- end -%>
10
+
11
+
@@ -0,0 +1,118 @@
1
+ require 'rails/generators/generated_attribute'
2
+
3
+ module ItiumTheme
4
+ class ThemedGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ argument :controller_path, :type => :string
8
+ argument :model_name, :type => :string, :required => false
9
+
10
+ class_option :will_paginate, :type => :boolean, :default => false, :desc => 'Specify if you use will_paginate'
11
+ class_option :themed_type, :type => :string, :default => 'crud', :desc => 'Specify the themed type, crud or text. Default is crud'
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
+ unless options.layout.blank?
21
+ if options.engine =~ /erb/
22
+ gsub_file(File.join('app/views/layouts', "#{options[:layout]}.html.#{options.engine}"), /\<div\s+id=\"main-navigation\">.*\<\/ul\>/mi) do |match|
23
+ match.gsub!(/\<\/ul\>/, "")
24
+ %|#{match} <li class="<%= controller.controller_path == '#{@controller_file_path}' ? 'active' : '' %>"><a href="<%= #{controller_routing_path}_path %>">#{plural_model_name}</a></li></ul>|
25
+ end
26
+ elsif options.engine =~ /haml/
27
+ gsub_file(File.join('app/views/layouts', "#{options[:layout]}.html.#{options.engine}"), /#main-navigation.*#wrapper.wat-cf/mi) do |match|
28
+ match.gsub!(/ #wrapper.wat-cf/, "")
29
+ %|#{match}| +
30
+ " "*6 + %|%li{:class => controller.controller_path == '#{@controller_file_path}' ? 'active' : '' }\n| +
31
+ " "*7 + %|%a{:href => #{controller_routing_path}_path} #{plural_model_name}\n| +
32
+ " "*3 + %|#wrapper.wat-cf|
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def initialize_views_variables
41
+ @base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
42
+ @controller_routing_path = @controller_file_path.gsub(/\//, '_')
43
+ @model_name = @base_name.singularize unless @model_name
44
+ @model_name = @model_name.camelize
45
+ end
46
+
47
+ def controller_routing_path
48
+ @controller_routing_path
49
+ end
50
+
51
+ def singular_controller_routing_path
52
+ @controller_routing_path.singularize
53
+ end
54
+
55
+ def model_name
56
+ @model_name
57
+ end
58
+
59
+ def plural_model_name
60
+ @model_name.pluralize
61
+ end
62
+
63
+ def resource_name
64
+ @model_name.underscore
65
+ end
66
+
67
+ def plural_resource_name
68
+ resource_name.pluralize
69
+ end
70
+
71
+ ##
72
+ # Attempts to call #columns on the model's class
73
+ # If the (Active Record) #columns method does not exist, it attempts to
74
+ # perform the (Mongoid) #fields method instead
75
+ def columns
76
+ begin
77
+ excluded_column_names = %w[id created_at updated_at]
78
+ Kernel.const_get(@model_name).columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
79
+ rescue NoMethodError
80
+ Kernel.const_get(@model_name).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)}
81
+ end
82
+ end
83
+
84
+ def extract_modules(name)
85
+ modules = name.include?('/') ? name.split('/') : name.split('::')
86
+ name = modules.pop
87
+ path = modules.map { |m| m.underscore }
88
+ file_path = (path + [name.underscore]).join('/')
89
+ nesting = modules.map { |m| m.camelize }.join('::')
90
+ [name, path, file_path, nesting, modules.size]
91
+ end
92
+
93
+ def generate_views
94
+ views = {
95
+ 'crud' => {
96
+ 'view_index.html.erb' => File.join('app/views', @controller_file_path, "index.html.erb"),
97
+ 'view_new.html.erb' => File.join('app/views', @controller_file_path, "new.html.erb"),
98
+ 'view_edit.html.erb' => File.join('app/views', @controller_file_path, "edit.html.erb"),
99
+ 'view_form.html.erb' => File.join('app/views', @controller_file_path, "_form.html.erb"),
100
+ 'view_show.html.erb' => File.join('app/views', @controller_file_path, "show.html.erb"),
101
+ 'view_search.html.erb' => File.join('app/views', @controller_file_path, "_search.html.erb")
102
+ },
103
+ 'ajax_crud' => {
104
+ 'view_ajax_crud.html.erb' => File.join('app/views', @controller_file_path, "index.html.erb")
105
+ }
106
+ }
107
+ selected_views = views[options.themed_type]
108
+ generate_erb_views(selected_views)
109
+ end
110
+
111
+ def generate_erb_views(views)
112
+ views.each do |template_name, output_path|
113
+ template template_name, output_path
114
+ end
115
+ end
116
+
117
+
118
+ end
@@ -0,0 +1,7 @@
1
+ require "itium-theme/version"
2
+
3
+ module ItiumTheme
4
+ class Engine < Rails::Engine
5
+
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Itium
2
+ module Theme
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itium-theme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hamilton Oliveira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-05 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: View generator for rails projects using simple_form and bootstrap
15
+ email:
16
+ - hamilton.oliveira@itium.com.br
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .project
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - itium-theme.gemspec
28
+ - lib/generators/itium_theme/themed/templates/view_ajax_crud.html.erb
29
+ - lib/generators/itium_theme/themed/templates/view_edit.html.erb
30
+ - lib/generators/itium_theme/themed/templates/view_form.html.erb
31
+ - lib/generators/itium_theme/themed/templates/view_index.html.erb
32
+ - lib/generators/itium_theme/themed/templates/view_new.html.erb
33
+ - lib/generators/itium_theme/themed/templates/view_search.html.erb
34
+ - lib/generators/itium_theme/themed/templates/view_show.html.erb
35
+ - lib/generators/itium_theme/themed/themed_generator.rb
36
+ - lib/itium-theme.rb
37
+ - lib/itium-theme/version.rb
38
+ homepage: ''
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.6
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: View generator for rails projects using simple_form and bootstrap
62
+ test_files: []