regulate 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +14 -0
- data/.rvmrc +1 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +117 -0
- data/LICENSE +20 -0
- data/README.md +3 -0
- data/Rakefile +10 -0
- data/app/controllers/regulate/admin/pages_controller.rb +69 -0
- data/app/controllers/regulate/pages_controller.rb +13 -0
- data/app/models/regulate/page.rb +21 -0
- data/app/views/regulate/admin/pages/_form.html.erb +36 -0
- data/app/views/regulate/admin/pages/edit.html.erb +1 -0
- data/app/views/regulate/admin/pages/index.html.erb +10 -0
- data/app/views/regulate/admin/pages/new.html.erb +1 -0
- data/app/views/regulate/pages/show.html.erb +14 -0
- data/config/regulate.yml +10 -0
- data/config/routes.rb +22 -0
- data/lib/generators/regulate/install_generator.rb +39 -0
- data/lib/generators/regulate/views_generator.rb +73 -0
- data/lib/generators/templates/regulate.css +2 -0
- data/lib/generators/templates/regulate.js +44 -0
- data/lib/generators/templates/regulate.rb +13 -0
- data/lib/generators/templates/regulate.yml +10 -0
- data/lib/regulate.rb +30 -0
- data/lib/regulate/engine.rb +50 -0
- data/lib/regulate/git.rb +17 -0
- data/lib/regulate/git/errors.rb +22 -0
- data/lib/regulate/git/interface.rb +249 -0
- data/lib/regulate/git/model.rb +16 -0
- data/lib/regulate/git/model/base.rb +282 -0
- data/lib/regulate/version.rb +4 -0
- data/public/javascripts/jquery.min.js +167 -0
- data/public/javascripts/regulate_admin.js +166 -0
- data/regulate.gemspec +29 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/regulate.yml +10 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +175 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/git_test.rb +79 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/models/regulate_git_model_base_lint_test.rb +7 -0
- data/test/models/regulate_git_model_base_test.rb +23 -0
- data/test/models/regulate_page_test.rb +19 -0
- data/test/regulate_test.rb +19 -0
- data/test/routing_test.rb +32 -0
- data/test/support/integration_case.rb +5 -0
- data/test/test_helper.rb +27 -0
- data/test/tmp/config/initializers/regulate.rb +12 -0
- data/test/tmp/config/regulate.yml +10 -0
- data/test/tmp/public/javascripts/regulate.js +49 -0
- data/test/tmp/public/stylesheets/regulate.css +3 -0
- metadata +312 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rvm use ruby-1.8.7-p302@regulate_vs2
|
data/.yardopts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
app/**/*.rb config/routes.rb lib/**/*.rb - README.md LICENSE
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
regulate (0.0.1)
|
|
5
|
+
grit (~> 2.3.0)
|
|
6
|
+
rails (~> 3.0.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: http://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
abstract (1.0.0)
|
|
12
|
+
actionmailer (3.0.3)
|
|
13
|
+
actionpack (= 3.0.3)
|
|
14
|
+
mail (~> 2.2.9)
|
|
15
|
+
actionpack (3.0.3)
|
|
16
|
+
activemodel (= 3.0.3)
|
|
17
|
+
activesupport (= 3.0.3)
|
|
18
|
+
builder (~> 2.1.2)
|
|
19
|
+
erubis (~> 2.6.6)
|
|
20
|
+
i18n (~> 0.4)
|
|
21
|
+
rack (~> 1.2.1)
|
|
22
|
+
rack-mount (~> 0.6.13)
|
|
23
|
+
rack-test (~> 0.5.6)
|
|
24
|
+
tzinfo (~> 0.3.23)
|
|
25
|
+
activemodel (3.0.3)
|
|
26
|
+
activesupport (= 3.0.3)
|
|
27
|
+
builder (~> 2.1.2)
|
|
28
|
+
i18n (~> 0.4)
|
|
29
|
+
activerecord (3.0.3)
|
|
30
|
+
activemodel (= 3.0.3)
|
|
31
|
+
activesupport (= 3.0.3)
|
|
32
|
+
arel (~> 2.0.2)
|
|
33
|
+
tzinfo (~> 0.3.23)
|
|
34
|
+
activeresource (3.0.3)
|
|
35
|
+
activemodel (= 3.0.3)
|
|
36
|
+
activesupport (= 3.0.3)
|
|
37
|
+
activesupport (3.0.3)
|
|
38
|
+
arel (2.0.6)
|
|
39
|
+
bluecloth (2.0.9)
|
|
40
|
+
builder (2.1.2)
|
|
41
|
+
capybara (0.4.0)
|
|
42
|
+
celerity (>= 0.7.9)
|
|
43
|
+
culerity (>= 0.2.4)
|
|
44
|
+
mime-types (>= 1.16)
|
|
45
|
+
nokogiri (>= 1.3.3)
|
|
46
|
+
rack (>= 1.0.0)
|
|
47
|
+
rack-test (>= 0.5.4)
|
|
48
|
+
selenium-webdriver (>= 0.0.27)
|
|
49
|
+
xpath (~> 0.1.2)
|
|
50
|
+
celerity (0.8.6)
|
|
51
|
+
childprocess (0.1.6)
|
|
52
|
+
ffi (~> 0.6.3)
|
|
53
|
+
culerity (0.2.13)
|
|
54
|
+
diff-lcs (1.1.2)
|
|
55
|
+
erubis (2.6.6)
|
|
56
|
+
abstract (>= 1.0.0)
|
|
57
|
+
ffi (0.6.3)
|
|
58
|
+
rake (>= 0.8.7)
|
|
59
|
+
grit (2.3.0)
|
|
60
|
+
diff-lcs (~> 1.1)
|
|
61
|
+
mime-types (~> 1.15)
|
|
62
|
+
i18n (0.5.0)
|
|
63
|
+
json_pure (1.4.6)
|
|
64
|
+
mail (2.2.13)
|
|
65
|
+
activesupport (>= 2.3.6)
|
|
66
|
+
i18n (>= 0.4.0)
|
|
67
|
+
mime-types (~> 1.16)
|
|
68
|
+
treetop (~> 1.4.8)
|
|
69
|
+
mime-types (1.16)
|
|
70
|
+
nokogiri (1.4.4)
|
|
71
|
+
polyglot (0.3.1)
|
|
72
|
+
rack (1.2.1)
|
|
73
|
+
rack-mount (0.6.13)
|
|
74
|
+
rack (>= 1.0.0)
|
|
75
|
+
rack-test (0.5.7)
|
|
76
|
+
rack (>= 1.0)
|
|
77
|
+
rails (3.0.3)
|
|
78
|
+
actionmailer (= 3.0.3)
|
|
79
|
+
actionpack (= 3.0.3)
|
|
80
|
+
activerecord (= 3.0.3)
|
|
81
|
+
activeresource (= 3.0.3)
|
|
82
|
+
activesupport (= 3.0.3)
|
|
83
|
+
bundler (~> 1.0)
|
|
84
|
+
railties (= 3.0.3)
|
|
85
|
+
railties (3.0.3)
|
|
86
|
+
actionpack (= 3.0.3)
|
|
87
|
+
activesupport (= 3.0.3)
|
|
88
|
+
rake (>= 0.8.7)
|
|
89
|
+
thor (~> 0.14.4)
|
|
90
|
+
rake (0.8.7)
|
|
91
|
+
rubyzip (0.9.4)
|
|
92
|
+
selenium-webdriver (0.1.2)
|
|
93
|
+
childprocess (~> 0.1.5)
|
|
94
|
+
ffi (~> 0.6.3)
|
|
95
|
+
json_pure
|
|
96
|
+
rubyzip
|
|
97
|
+
sqlite3-ruby (1.3.2)
|
|
98
|
+
thor (0.14.6)
|
|
99
|
+
treetop (1.4.9)
|
|
100
|
+
polyglot (>= 0.3.1)
|
|
101
|
+
tzinfo (0.3.23)
|
|
102
|
+
xpath (0.1.2)
|
|
103
|
+
nokogiri (~> 1.3)
|
|
104
|
+
yard (0.6.4)
|
|
105
|
+
|
|
106
|
+
PLATFORMS
|
|
107
|
+
ruby
|
|
108
|
+
|
|
109
|
+
DEPENDENCIES
|
|
110
|
+
bluecloth (~> 2.0.9)
|
|
111
|
+
bundler (~> 1.0.0)
|
|
112
|
+
capybara (~> 0.4.0)
|
|
113
|
+
grit (~> 2.3.0)
|
|
114
|
+
rails (~> 3.0.0)
|
|
115
|
+
regulate!
|
|
116
|
+
sqlite3-ruby (~> 1.3.2)
|
|
117
|
+
yard (~> 0.6.4)
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2010 Quick Left, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module Regulate
|
|
2
|
+
|
|
3
|
+
# Our admin namespace to contain any related controllers
|
|
4
|
+
module Admin
|
|
5
|
+
|
|
6
|
+
# Standard CRUD Controller
|
|
7
|
+
class PagesController < ActionController::Base
|
|
8
|
+
# Load in our page object based on the ID
|
|
9
|
+
before_filter :load_page, :only => [:edit,:update,:destroy]
|
|
10
|
+
|
|
11
|
+
# POST route to create a new page
|
|
12
|
+
def create
|
|
13
|
+
if Regulate::Page.create!(params[:page])
|
|
14
|
+
flash[:notice] = "Page created!"
|
|
15
|
+
redirect_to regulate_admin_regulate_pages_path
|
|
16
|
+
else
|
|
17
|
+
render :action => :new
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# GET skeleton method to get to an edit page
|
|
22
|
+
def edit; end
|
|
23
|
+
|
|
24
|
+
# PUT method to persist changes to a Page object
|
|
25
|
+
def update
|
|
26
|
+
if @page.update_attributes(params[:page])
|
|
27
|
+
flash[:notice] = "Successfully updated #{params[:page][:title]}"
|
|
28
|
+
redirect_to regulate_admin_regulate_pages_path
|
|
29
|
+
else
|
|
30
|
+
render :action => :edit
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# GET method to show new Page form
|
|
35
|
+
def new
|
|
36
|
+
@page = Regulate::Page.new
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# DELETE method to destroy a page
|
|
40
|
+
def destroy
|
|
41
|
+
@page.destroy
|
|
42
|
+
flash[:notice] = "Page deleted."
|
|
43
|
+
redirect_to regulate_admin_regulate_pages_path
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# GET skeleton method to show a list of pages
|
|
47
|
+
def index
|
|
48
|
+
@pages = Regulate::Page.find_all
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# GET method to view a page
|
|
52
|
+
# Render the edit action
|
|
53
|
+
def show
|
|
54
|
+
render :action => :edit
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
# Grab a page resource based on the ID passed to the URI
|
|
60
|
+
def load_page
|
|
61
|
+
@page = Regulate::Page.find(params[:id])
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end # class PagesController
|
|
65
|
+
|
|
66
|
+
end # module Admin
|
|
67
|
+
|
|
68
|
+
end # module Regulate
|
|
69
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Regulate
|
|
2
|
+
|
|
3
|
+
# @todo Build out XHR-only methods for frontend inline editing
|
|
4
|
+
class PagesController < ActionController::Base
|
|
5
|
+
|
|
6
|
+
# Show function for front-end
|
|
7
|
+
def show
|
|
8
|
+
@page = Regulate::Page.find(params[:id])
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end # class PagesController
|
|
12
|
+
|
|
13
|
+
end # class Regulate
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Regulate
|
|
2
|
+
|
|
3
|
+
# The standard model for our CMS engine
|
|
4
|
+
class Page < Regulate::Git::Model::Base
|
|
5
|
+
|
|
6
|
+
# A title= override so that we are setting a URI-friendly id
|
|
7
|
+
#
|
|
8
|
+
# @param [String] The new title of our page
|
|
9
|
+
# @return [NilClass]
|
|
10
|
+
def title=(new_title)
|
|
11
|
+
@title = new_title
|
|
12
|
+
# Make sure that we're setting our ID.
|
|
13
|
+
# This needs to be URI-friendly
|
|
14
|
+
#@id = self.title.gsub(%r{[ /<>]}, '-').downcase
|
|
15
|
+
@id = self.title.gsub(/[^a-zA-Z0-9']+/, "-").chomp('-').reverse.chomp('-').reverse.downcase
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<style type="text/css">
|
|
2
|
+
fieldset {width:600px;float:left;}
|
|
3
|
+
.form_row, label, textarea, #page_title {clear:both;width:100%;float:left;}
|
|
4
|
+
label {padding:10px 0;text-transform:capitalize;}
|
|
5
|
+
textarea {height:250px;}
|
|
6
|
+
#edit_regions textarea {height:150px;}
|
|
7
|
+
.form_row {padding:10px 0 10px 0;}
|
|
8
|
+
</style>
|
|
9
|
+
|
|
10
|
+
<%= form_for([:regulate , :admin , @page], :as => :page) do |f| %>
|
|
11
|
+
<fieldset id="page_form">
|
|
12
|
+
<div id="custom_field_errors"></div>
|
|
13
|
+
<% if !@page.persisted? %>
|
|
14
|
+
<div class="form_row">
|
|
15
|
+
<%= f.label :title %>
|
|
16
|
+
<%= f.text_field :title %>
|
|
17
|
+
</div>
|
|
18
|
+
<% else %>
|
|
19
|
+
<div class="form_row">
|
|
20
|
+
Title: <%= @page.title %>
|
|
21
|
+
</div>
|
|
22
|
+
<% end %>
|
|
23
|
+
<div class="form_row">
|
|
24
|
+
<%= f.label :view %>
|
|
25
|
+
<%= f.text_area :view %>
|
|
26
|
+
</div>
|
|
27
|
+
<div id="edit_regions"></div>
|
|
28
|
+
<div class="form_row">
|
|
29
|
+
<%= f.submit "Save" %>
|
|
30
|
+
<%= link_to "Cancel" , regulate_admin_regulate_pages_path %>
|
|
31
|
+
</div>
|
|
32
|
+
</fieldset>
|
|
33
|
+
<% end %>
|
|
34
|
+
<%= javascript_tag "var existing_custom_fields = #{@page.edit_regions.to_json}" %>
|
|
35
|
+
<%= javascript_include_tag "jquery.min.js" %>
|
|
36
|
+
<%= javascript_include_tag "regulate_admin" %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render "form" %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render "form" %>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<h2><%= @page.title %></h2>
|
|
2
|
+
<cite>by, <%= @page.versions.first.author.name %></cite>
|
|
3
|
+
<div>
|
|
4
|
+
<%= raw @page.rendered %>
|
|
5
|
+
</div>
|
|
6
|
+
<ul>
|
|
7
|
+
<% @page.versions.each do |version| %>
|
|
8
|
+
<li>
|
|
9
|
+
Author: <%= version.author.name %><br />
|
|
10
|
+
Commit Message: <%= version.message %><br />
|
|
11
|
+
Authored Date: <%= version.authored_date %>
|
|
12
|
+
</li>
|
|
13
|
+
<% end %>
|
|
14
|
+
</ul>
|
data/config/regulate.yml
ADDED
data/config/routes.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Rails.application.routes.draw do
|
|
2
|
+
|
|
3
|
+
# Load our engine's routes in to the host app:
|
|
4
|
+
# - Load our route namespace directly from the engine gem
|
|
5
|
+
# - Use the Regulate module
|
|
6
|
+
# - Make sure our route names are namespaced under regulate_
|
|
7
|
+
scope Regulate.route_namespace, :module => :regulate, :as => :regulate do
|
|
8
|
+
|
|
9
|
+
# Only allow the show action publicly
|
|
10
|
+
resources :pages, :only => [ :show ]
|
|
11
|
+
|
|
12
|
+
# In the admin, allow all actions
|
|
13
|
+
# Ensure that we're setting our scoping options properly:
|
|
14
|
+
# - namespaced to "admin"
|
|
15
|
+
# - under the Admin module
|
|
16
|
+
# - the route names namespaced under admin_
|
|
17
|
+
scope "admin", :module => :admin, :as => :admin_regulate do
|
|
18
|
+
resources :pages
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Regulate
|
|
2
|
+
|
|
3
|
+
# Top level generators module to hold any generators for our engine gem
|
|
4
|
+
module Generators
|
|
5
|
+
|
|
6
|
+
# Standard install that lets a user copy files over so they can override some functionality
|
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
|
8
|
+
|
|
9
|
+
# Tell Rails where to find our templates
|
|
10
|
+
source_root File.expand_path("../../templates", __FILE__)
|
|
11
|
+
|
|
12
|
+
desc "Copies files to your application that regulate needs."
|
|
13
|
+
|
|
14
|
+
# Copy over our CSS
|
|
15
|
+
def copy_css
|
|
16
|
+
template "regulate.css", "public/stylesheets/regulate.css"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Copy over our JS
|
|
20
|
+
def copy_js
|
|
21
|
+
template "regulate.js", "public/javascripts/regulate.js"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Copy over the repo config YAML file
|
|
25
|
+
def copy_yml
|
|
26
|
+
template "regulate.yml", "config/regulate.yml"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Copy over the Regulate initializer
|
|
30
|
+
def copy_initializer
|
|
31
|
+
template "regulate.rb", "config/initializers/regulate.rb"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end # class InstallGenerator
|
|
35
|
+
|
|
36
|
+
end # Generators
|
|
37
|
+
|
|
38
|
+
end # module Regulate
|
|
39
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Regulate
|
|
2
|
+
|
|
3
|
+
module Generators
|
|
4
|
+
|
|
5
|
+
# Class lifted from Devise. Thanks josevalim!
|
|
6
|
+
class ViewsGenerator < Rails::Generators::Base
|
|
7
|
+
|
|
8
|
+
# Tell Rails where our view files are
|
|
9
|
+
source_root File.expand_path("../../../../app/views", __FILE__)
|
|
10
|
+
desc "Copies all Regulate views to your application in app/views/pages."
|
|
11
|
+
|
|
12
|
+
class_option :template_engine, :type => :string, :aliases => "-t",
|
|
13
|
+
:desc => "Template engine for the views. Available options are 'erb' and 'haml'."
|
|
14
|
+
|
|
15
|
+
# Copy over our view files
|
|
16
|
+
def copy_views
|
|
17
|
+
case options[:template_engine].to_s
|
|
18
|
+
when "haml"
|
|
19
|
+
verify_haml_existence
|
|
20
|
+
verify_haml_version
|
|
21
|
+
create_and_copy_haml_views
|
|
22
|
+
else
|
|
23
|
+
directory "pages", "app/views/pages"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
# Check whether the current environment has HAML
|
|
30
|
+
def verify_haml_existence
|
|
31
|
+
begin
|
|
32
|
+
require 'haml'
|
|
33
|
+
rescue LoadError
|
|
34
|
+
say "HAML is not installed, or it is not specified in your Gemfile."
|
|
35
|
+
exit
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Make sure we have the right HAML version
|
|
40
|
+
def verify_haml_version
|
|
41
|
+
unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3
|
|
42
|
+
say "To generate HAML templates, you need to install HAML 2.3 or above."
|
|
43
|
+
exit
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Copy over the HAML files
|
|
48
|
+
def create_and_copy_haml_views
|
|
49
|
+
require 'tmpdir'
|
|
50
|
+
html_root = "#{self.class.source_root}/pages"
|
|
51
|
+
|
|
52
|
+
Dir.mktmpdir("regulate-haml.") do |haml_root|
|
|
53
|
+
Dir["#{html_root}/**/*"].each do |path|
|
|
54
|
+
relative_path = path.sub(html_root, "")
|
|
55
|
+
source_path = (haml_root + relative_path).sub(/erb$/, "haml")
|
|
56
|
+
|
|
57
|
+
if File.directory?(path)
|
|
58
|
+
FileUtils.mkdir_p(source_path)
|
|
59
|
+
else
|
|
60
|
+
`html2haml -r #{path} #{source_path}`
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
directory haml_root, "app/views/pages"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end # class ViewsGenerator
|
|
69
|
+
|
|
70
|
+
end # module Generators
|
|
71
|
+
|
|
72
|
+
end # module Regulate
|
|
73
|
+
|