foundationize 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ *.sublime-project
19
+ *.sublime-workspace
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foundationize.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eptikar IT Solutions Inc.
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.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Foundationize
2
+
3
+ Foundationize is a ruby gem to ease the use of ZURB Foundation with rails apps. It's consists of:
4
+ - Generators to foundationize you views.
5
+ - Helpers to save you some time when you're foundationing.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'foundationize'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install foundationize
21
+
22
+ ## Usage
23
+
24
+ $ rails g foundationize posts
25
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foundationize/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "foundationize"
8
+ spec.version = Foundationize::VERSION
9
+ spec.authors = ["Mohanad Najeeb"]
10
+ spec.email = ["mohanad.najeeb@eptikar.com"]
11
+ spec.description = %q{Foundationize is a ruby gem to ease the use of ZURB Foundation with rails apps.}
12
+ spec.summary = %q{Scaffold generators.}
13
+ spec.homepage = "https://github.com/Eptikar-IT-Solutions/foundationize"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'zurb-foundation', '~> 4.2.3'
24
+
25
+ end
@@ -0,0 +1,6 @@
1
+ require "foundationize/version"
2
+ require 'foundationize/railtie' if defined?(Rails::Railtie)
3
+
4
+ module Foundationize
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,78 @@
1
+ module Foundationize
2
+
3
+ module ViewHelpers
4
+
5
+ def foundationize_flash
6
+ flash_messages = []
7
+ flash.each do |type, message|
8
+
9
+ next if message.blank?
10
+
11
+ type = :alert if type == :error
12
+ type = :success if type == :success
13
+ type = :secondary if type == :notice
14
+
15
+ Array(message).each do |msg|
16
+ flash = raw("<div data-alert class=\"alert-box #{type}\">#{msg.html_safe}<a href=\"#\" class=\"close\">&times;</a></div>");
17
+ flash_messages << flash if msg
18
+ end
19
+ end
20
+ flash_messages.join("\n").html_safe
21
+ end
22
+
23
+ def top_bar(options={}, &block)
24
+ content_tag :nav, class: "top-bar" do
25
+ content = ""
26
+ content += content_tag :li, content_tag(:h1, link_to(options[:title],"#")), class: "name"
27
+ content += content_tag :li, link_to(options[:text], "#"), class: options[:icon] ? "toggle-topbar menu-icon" : "toggle-topbar"
28
+
29
+ html = content_tag :ul, raw(content), class: "title-area"
30
+
31
+ content = capture(&block)
32
+ html +=content_tag :section, content, class: "top-bar-section"
33
+ raw html
34
+ end
35
+ end
36
+
37
+ def left_section(&block)
38
+ top_bar_section("left", &block)
39
+ end
40
+
41
+ def right_section(&block)
42
+ top_bar_section("right", &block)
43
+ end
44
+
45
+ def top_bar_section(direction, &block)
46
+ content_tag :ul, class: direction do
47
+ yield
48
+ end
49
+ end
50
+
51
+ def menu_item(url, text, options={})
52
+ html = ""
53
+ html += menu_divider if options[:divider]
54
+ html += content_tag :li, link_to(url,text), class: options[:active] ? "active" : ""
55
+ raw html
56
+ end
57
+
58
+ def menu_label(text)
59
+ content_tag :li, content_tag(:label,text)
60
+ end
61
+
62
+ def dropdown_menu(url, text, options={}, &block)
63
+ html = ""
64
+ content_tag :li, class: options[:active] ? "has-dropdown active" : "has-dropdown" do
65
+ html += link_to(url,text)
66
+ content = capture(&block)
67
+ html += content_tag :ul, content, class: "dropdown"
68
+ raw html
69
+ end
70
+ end
71
+
72
+ def menu_divider (hide = false)
73
+ content_tag :li, nil, class: hide ? "divider hide-for-small" : "divider"
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,9 @@
1
+ require 'foundationize/foundationize_viewhelpers'
2
+
3
+ module Foundationize
4
+ class Railtie < Rails::Railtie
5
+ initializer "foundationize.view_helpers" do
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Foundationize
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,141 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/generated_attribute'
3
+
4
+ class FoundationizeGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ argument :controller_path, :type => :string
7
+ argument :model_name, :type => :string, :required => false
8
+ argument :layout, :type => :string, :default => "application",
9
+ :banner => "Specify application layout"
10
+
11
+ class_option :excluded_columns, :type => :array, :required => false
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_name
40
+ @model_name
41
+ end
42
+
43
+ def plural_model_name
44
+ @model_name.pluralize
45
+ end
46
+
47
+ def resource_name
48
+ @model_name.demodulize.underscore
49
+ end
50
+
51
+ def plural_resource_name
52
+ resource_name.pluralize
53
+ end
54
+
55
+ def columns
56
+ retrieve_columns.reject {|c| excluded?(c.name) }.map do |c|
57
+ new_attribute(c.name, c.type.to_s)
58
+ end
59
+ end
60
+
61
+ def excluded_columns_names
62
+ %w[_id _type id created_at updated_at]
63
+ end
64
+
65
+ def excluded_columns_pattern
66
+ [
67
+ /.*_checksum/,
68
+ /.*_count/,
69
+ ]
70
+ end
71
+
72
+ def excluded_columns
73
+ options['excluded_columns']||[]
74
+ end
75
+
76
+ def excluded?(name)
77
+ excluded_columns_names.include?(name) ||
78
+ excluded_columns_pattern.any? {|p| name =~ p } ||
79
+ excluded_columns.include?(name)
80
+ end
81
+
82
+ def retrieve_columns
83
+ if defined?(ActiveRecord) == "constant" && ActiveRecord.class == Module
84
+ rescue_block ActiveRecord::StatementInvalid do
85
+ @model_name.constantize.columns
86
+ end
87
+ else
88
+ rescue_block do
89
+ @model_name.constantize.fields.map {|c| c[1] }
90
+ end
91
+ end
92
+ end
93
+
94
+ def new_attribute(name, type)
95
+ ::Rails::Generators::GeneratedAttribute.new(name, type)
96
+ end
97
+
98
+ def rescue_block(exception=Exception)
99
+ yield if block_given?
100
+ rescue exception => e
101
+ say e.message, :red
102
+ exit
103
+ end
104
+
105
+ def extract_modules(name)
106
+ modules = name.include?('/') ? name.split('/') : name.split('::')
107
+ name = modules.pop
108
+ path = modules.map { |m| m.underscore }
109
+ file_path = (path + [name.underscore]).join('/')
110
+ nesting = modules.map { |m| m.camelize }.join('::')
111
+ [name, path, file_path, nesting, modules.size]
112
+ end
113
+
114
+ def generate_views
115
+ options.engine == generate_erb(selected_views)
116
+ end
117
+
118
+ def selected_views
119
+ {
120
+ "index.html.erb" => File.join('app/views', @controller_file_path, "index.html.erb"),
121
+ "new.html.erb" => File.join('app/views', @controller_file_path, "new.html.erb"),
122
+ "edit.html.erb" => File.join('app/views', @controller_file_path, "edit.html.erb"),
123
+ "#{form_builder}_form.html.erb" => File.join('app/views', @controller_file_path, "_form.html.erb"),
124
+ "show.html.erb" => File.join('app/views', @controller_file_path, "show.html.erb")
125
+ }
126
+ end
127
+
128
+ def generate_erb(views)
129
+ views.each do |template_name, output_path|
130
+ template template_name, output_path
131
+ end
132
+ end
133
+
134
+ def ext
135
+ ::Rails.application.config.generators.options[:rails][:template_engine] || :erb
136
+ end
137
+
138
+ def form_builder
139
+ defined?(::SimpleForm) ? 'simple_form/' : ''
140
+ end
141
+ end
@@ -0,0 +1,18 @@
1
+ <%%= form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f| %>
2
+ <%- columns.each do |column| -%>
3
+ <div class="row">
4
+ <div class="large-12 columns">
5
+ <%%= f.label :<%= column.name %> %>
6
+ <%%= f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>' %>
7
+ </div>
8
+ </div>
9
+ <%- end -%>
10
+
11
+ <div class="row">
12
+ <div class="large-12 columns">
13
+ <%%= f.submit nil, :class => 'button success' %>
14
+ <%%= link_to t('.cancel', :default => t("helpers.links.cancel")),
15
+ <%= controller_routing_path %>_path, :class => 'button alert' %>
16
+ </div>
17
+ </div>
18
+ <%% end %>
@@ -0,0 +1,7 @@
1
+ <%%- model_class = <%= resource_name.classify %> -%>
2
+ <div class="row">
3
+ <div class="large-12 columns">
4
+ <h1><%%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human.titleize %></h1>
5
+ </div>
6
+ </div>
7
+ <%%= render :partial => 'form' %>
@@ -0,0 +1,41 @@
1
+ <%%- model_class = <%= resource_name.classify %> -%>
2
+ <div class="row">
3
+ <div class="large-12 columns">
4
+ <h1><%%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
5
+
6
+ <table>
7
+ <thead>
8
+ <tr>
9
+ <th><%%= model_class.human_attribute_name(:id) %></th>
10
+ <%- columns.each do |column| -%>
11
+ <th><%%= model_class.human_attribute_name(:<%= column.name %>) %></th>
12
+ <%- end -%>
13
+ <th><%%= model_class.human_attribute_name(:created_at) %></th>
14
+ <th><%%=t '.actions', :default => t("helpers.actions") %></th>
15
+ </tr>
16
+ </thead>
17
+ <tbody>
18
+ <%% @<%= plural_resource_name %>.each do |<%= resource_name %>| %>
19
+ <tr>
20
+ <td><%%= link_to <%= resource_name %>.id, <%= singular_controller_routing_path %>_path(<%= resource_name %>) %></td>
21
+ <%- columns.each do |column| -%>
22
+ <td><%%= <%= resource_name %>.<%= column.name %> %></td>
23
+ <%- end -%>
24
+ <td><%%=l <%= resource_name %>.created_at %></td>
25
+ <td>
26
+ <%%= link_to t('.edit', :default => t("helpers.links.edit")),
27
+ edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-mini' %>
28
+ <%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
29
+ <%= singular_controller_routing_path %>_path(<%= resource_name %>),
30
+ :method => :delete,
31
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
32
+ :class => 'btn btn-mini btn-danger' %>
33
+ </td>
34
+ </tr>
35
+ <%% end %>
36
+ </tbody>
37
+ </table>
38
+
39
+ <%%= link_to t('.new', :default => t("helpers.links.new")),
40
+ new_<%= singular_controller_routing_path %>_path,
41
+ :class => 'button' %>
@@ -0,0 +1,8 @@
1
+ <%%- model_class = <%= resource_name.classify %> -%>
2
+ <div class="row">
3
+ <div class="large-12 columns">
4
+ <h1><%%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize %></h1>
5
+ </div>
6
+ </div>
7
+
8
+ <%%= render :partial => 'form' %>
@@ -0,0 +1,25 @@
1
+ <%%- model_class = <%= resource_name.classify %> -%>
2
+ <div class="row">
3
+ <div class="large-12 columns">
4
+ <h1><%%=t '.title', :default => model_class.model_name.human.titleize %></h1>
5
+
6
+ <%- columns.each do |column| -%>
7
+ <p>
8
+ <strong><%%= model_class.human_attribute_name(:<%= column.name %>) %>:</strong>
9
+ <%%= @<%= resource_name %>.<%= column.name %> %>
10
+ </p>
11
+ <%- end -%>
12
+
13
+ <div class="panel">
14
+ <%%= link_to t('.back', :default => t("helpers.links.back")),
15
+ <%= controller_routing_path %>_path, :class => 'button' %>
16
+ <%%= link_to t('.edit', :default => t("helpers.links.edit")),
17
+ edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'button' %>
18
+ <%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
19
+ <%= singular_controller_routing_path %>_path(@<%= resource_name %>),
20
+ :method => 'delete',
21
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
22
+ :class => 'button' %>
23
+ </div>
24
+ </div>
25
+ </div>
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foundationize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mohanad Najeeb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ name: zurb-foundation
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: 4.2.3
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: 4.2.3
59
+ none: false
60
+ prerelease: false
61
+ type: :development
62
+ description: Foundationize is a ruby gem to ease the use of ZURB Foundation with rails apps.
63
+ email:
64
+ - mohanad.najeeb@eptikar.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - foundationize.gemspec
75
+ - lib/foundationize.rb
76
+ - lib/foundationize/foundationize_viewhelpers.rb
77
+ - lib/foundationize/railtie.rb
78
+ - lib/foundationize/version.rb
79
+ - lib/generators/foundationize_generator.rb
80
+ - lib/generators/templates/_form.html.erb
81
+ - lib/generators/templates/edit.html.erb
82
+ - lib/generators/templates/index.html.erb
83
+ - lib/generators/templates/new.html.erb
84
+ - lib/generators/templates/show.html.erb
85
+ homepage: https://github.com/Eptikar-IT-Solutions/foundationize
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ none: false
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ none: false
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.24
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Scaffold generators.
110
+ test_files: []