prague 0.0.1 → 0.0.2
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/lib/generators/prague/model/model_generator.rb +2 -2
- data/lib/generators/prague/model/templates/migration.rb.erb +1 -0
- data/lib/generators/prague/model/templates/model.rb.erb +14 -1
- data/lib/generators/prague/scaffold/scaffold_generator.rb +15 -4
- data/lib/generators/prague/scaffold/templates/helper.rb.erb +3 -5
- data/lib/generators/prague/scaffold/templates/view.html.erb.erb +12 -2
- data/lib/prague/version.rb +1 -1
- data/test/dummy/log/test.log +9 -0
- metadata +4 -8
- data/lib/generators/prague/scaffold/templates/route.rb.erb +0 -4
@@ -4,7 +4,7 @@ module Prague
|
|
4
4
|
module Generators
|
5
5
|
class ModelGenerator < ::ActiveRecord::Generators::Base
|
6
6
|
desc 'This generator generates a model for pages'
|
7
|
-
argument :name, default: '
|
7
|
+
argument :name, default: 'page'
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
9
|
|
10
10
|
def create_migration
|
@@ -12,7 +12,7 @@ module Prague
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_model
|
15
|
-
template 'model.rb.erb', "app/models/#{
|
15
|
+
template 'model.rb.erb', "app/models/#{singular_name}.rb"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -5,6 +5,7 @@ class PragueCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
5
5
|
t.string :permalink, null: false, uniq: true
|
6
6
|
t.string :link_title, null: false
|
7
7
|
t.string :sort_value, limit: 100
|
8
|
+
t.text :head, null: false
|
8
9
|
t.text :body, null: false
|
9
10
|
t.boolean :online, default: false
|
10
11
|
end
|
@@ -1,10 +1,23 @@
|
|
1
|
+
# Prague-model for pages.
|
2
|
+
#
|
3
|
+
# Attributes:
|
4
|
+
#
|
5
|
+
# title - Title of the page.
|
6
|
+
# permalink - Path the page should be accessed by.
|
7
|
+
# link_title - Title for links in views.
|
8
|
+
# sort_value - Pages are returned sorted by the the sort_value by default.
|
9
|
+
# head - Content for meta tags for the page.
|
10
|
+
# body - Content for main content of the page.
|
11
|
+
# online - Whether or not the page should be visible to the outside world.
|
12
|
+
#
|
1
13
|
class <%= class_name %> < ActiveRecord::Base
|
2
|
-
attr_accessible :title, :permalink, :link_title, :sort_value, :body, :online
|
14
|
+
attr_accessible :title, :permalink, :link_title, :sort_value, :head, :body, :online
|
3
15
|
|
4
16
|
validates :title, presence: true
|
5
17
|
validates :permalink, presence: true, uniqueness: true
|
6
18
|
validates :link_title, presence: true
|
7
19
|
validates :sort_value, length: {maximum: 100}
|
20
|
+
validates :head, presence: true
|
8
21
|
validates :body, presence: true
|
9
22
|
|
10
23
|
default_scope order('sort_value DESC')
|
@@ -4,7 +4,7 @@ module Prague
|
|
4
4
|
include Rails::Generators::ResourceHelpers
|
5
5
|
|
6
6
|
desc 'This generator generates a scaffold for pages'
|
7
|
-
argument :name, default: '
|
7
|
+
argument :name, default: 'page'
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
9
|
|
10
10
|
def create_model_and_migration
|
@@ -12,7 +12,8 @@ module Prague
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_controller
|
15
|
-
|
15
|
+
generate 'scaffold_controller', singular_name.classify +
|
16
|
+
' title permalink link_title sort_value head:text body:text online:boolean'
|
16
17
|
inject_into_class "app/controllers/#{plural_name}_controller.rb",
|
17
18
|
"#{controller_class_name}Controller", erb('action.rb.erb')
|
18
19
|
end
|
@@ -21,14 +22,24 @@ module Prague
|
|
21
22
|
template 'view.html.erb.erb', "app/views/#{plural_name}/display.html.erb"
|
22
23
|
end
|
23
24
|
|
25
|
+
def add_display_link_to_show_view
|
26
|
+
append_to_file "app/views/#{plural_name}/show.html.erb",
|
27
|
+
"| <%= link_to 'Display', display_#{singular_name}_path(permalink: @#{singular_name}.permalink) %>"
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_meta_tags_to_application_layout
|
31
|
+
gsub_file 'app/views/layouts/application.html.erb', '</head>',
|
32
|
+
" <%= content_for :meta_tags if content_for? :meta_tags %>\n</head>"
|
33
|
+
end
|
34
|
+
|
24
35
|
def create_display_helper
|
25
36
|
template 'helper.rb.erb', "app/helpers/#{plural_name}_display_helper.rb"
|
26
37
|
end
|
27
38
|
|
28
39
|
def add_routes
|
29
|
-
route
|
40
|
+
route "\n resources :#{plural_name}"
|
30
41
|
gsub_file 'config/routes.rb', /end\Z/,
|
31
|
-
"\n match ':permalink' => '#{plural_name}#display'\nend"
|
42
|
+
"\n match ':permalink' => '#{plural_name}#display', as: 'display_#{singular_name}'\nend"
|
32
43
|
end
|
33
44
|
|
34
45
|
private
|
@@ -2,7 +2,6 @@ module <%= plural_name.camelize %>DisplayHelper
|
|
2
2
|
#
|
3
3
|
# Helper for linking to <%= plural_name %> with a fallback.
|
4
4
|
# html_options are the same as for link_to helper.
|
5
|
-
# Additionally you can switch between link_to and link_to_unless_current with option unless_current.
|
6
5
|
#
|
7
6
|
# link_to_display_<%= singular_name %> 'about'
|
8
7
|
# # => <a href="/about" title="About's link title">About's link title</a>
|
@@ -26,17 +25,16 @@ module <%= plural_name.camelize %>DisplayHelper
|
|
26
25
|
# If the <%= singular_name %> doesn't exist and you want to display just nothing use the unless_missing option.
|
27
26
|
#
|
28
27
|
def link_to_display_<%= singular_name %>(permalink, html_options={})
|
29
|
-
method_name = html_options.delete(:unless_current) ? :link_to_unless_current : :link_to
|
30
28
|
unless_missing = html_options.delete :unless_missing
|
31
|
-
if <%= singular_name %> = <%= plural_name.classify %>.find_by_permalink
|
29
|
+
if <%= singular_name %> = <%= plural_name.classify %>.find_by_permalink(permalink)
|
32
30
|
url = display_<%= singular_name %>_path permalink: <%= singular_name %>.permalink
|
33
31
|
html_options = html_options.reverse_merge title: <%= singular_name %>.link_title
|
34
32
|
if block_given?
|
35
|
-
|
33
|
+
link_to url, html_options do
|
36
34
|
yield <%= singular_name %>
|
37
35
|
end
|
38
36
|
else
|
39
|
-
|
37
|
+
link_to <%= singular_name %>.link_title, url, html_options
|
40
38
|
end
|
41
39
|
elsif !unless_missing
|
42
40
|
link_to permalink, "##{permalink}", title: t('prague.missing.<%= singular_name %>',
|
@@ -1,7 +1,17 @@
|
|
1
|
+
<%% if @<%= singular_name %>.head.present? %>
|
2
|
+
<%%= content_for :meta_tags do %>
|
3
|
+
<%%= raw @<%=singular_name%>.head %>
|
4
|
+
<%% end %>
|
5
|
+
<%% end %>
|
6
|
+
|
1
7
|
<h1><%%= @<%= singular_name %>.title %></h1>
|
2
8
|
<p><%%= raw @<%= singular_name %>.body %></p>
|
3
9
|
<ul>
|
4
|
-
<%% <%= plural_name.classify %>.online.each do
|
5
|
-
<li
|
10
|
+
<%% <%= plural_name.classify %>.online.each do |<%= singular_name %>| %>
|
11
|
+
<li>
|
12
|
+
<%%= link_to_display_<%= singular_name %> <%= singular_name %>.permalink do |<%= singular_name.first %>| %>
|
13
|
+
<b><%%= <%= singular_name.first %>.title %></b>
|
14
|
+
<%% end %>
|
15
|
+
</li>
|
6
16
|
<%% end %>
|
7
17
|
</ul>
|
data/lib/prague/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -4,3 +4,12 @@ Connecting to database specified by database.yml
|
|
4
4
|
Connecting to database specified by database.yml
|
5
5
|
[1m[36m (0.4ms)[0m [1mbegin transaction[0m
|
6
6
|
[1m[35m (0.0ms)[0m rollback transaction
|
7
|
+
Connecting to database specified by database.yml
|
8
|
+
[1m[36m (2.8ms)[0m [1mbegin transaction[0m
|
9
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
10
|
+
Connecting to database specified by database.yml
|
11
|
+
[1m[36m (3.7ms)[0m [1mbegin transaction[0m
|
12
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
13
|
+
Connecting to database specified by database.yml
|
14
|
+
[1m[36m (4.1ms)[0m [1mbegin transaction[0m
|
15
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prague
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-09-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -56,7 +56,6 @@ files:
|
|
56
56
|
- lib/generators/prague/scaffold/scaffold_generator.rb
|
57
57
|
- lib/generators/prague/scaffold/templates/action.rb.erb
|
58
58
|
- lib/generators/prague/scaffold/templates/helper.rb.erb
|
59
|
-
- lib/generators/prague/scaffold/templates/route.rb.erb
|
60
59
|
- lib/generators/prague/scaffold/templates/view.html.erb.erb
|
61
60
|
- lib/prague/version.rb
|
62
61
|
- lib/prague.rb
|
@@ -105,10 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
104
|
requirements:
|
106
105
|
- - ! '>='
|
107
106
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
109
|
-
segments:
|
110
|
-
- 0
|
111
|
-
hash: -3324856822940849551
|
107
|
+
version: 1.9.3
|
112
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
109
|
none: false
|
114
110
|
requirements:
|
@@ -117,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
113
|
version: '0'
|
118
114
|
segments:
|
119
115
|
- 0
|
120
|
-
hash:
|
116
|
+
hash: 4527774159099249935
|
121
117
|
requirements: []
|
122
118
|
rubyforge_project:
|
123
119
|
rubygems_version: 1.8.23
|