thesis 0.1.1 → 0.1.3
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.
- checksums.yaml +7 -0
- data/README.md +103 -68
- data/app/assets/javascripts/thesis.js +1 -0
- data/app/assets/javascripts/thesis/thesis.coffee +250 -0
- data/app/assets/javascripts/thesis/utilities.coffee +13 -0
- data/app/assets/stylesheets/thesis.sass +4 -0
- data/app/assets/stylesheets/thesis/_mixins/_barber-pole.sass +5 -0
- data/app/assets/stylesheets/thesis/_mixins/editor.sass +15 -0
- data/app/assets/stylesheets/thesis/_thesis.sass +207 -0
- data/app/assets/stylesheets/thesis/base/_base.sass +5 -0
- data/app/assets/stylesheets/thesis/base/_colors.sass +6 -0
- data/app/assets/stylesheets/thesis/base/_fonts.sass +6 -0
- data/app/assets/stylesheets/thesis/base/_forms.scss +165 -0
- data/app/assets/stylesheets/thesis/base/_keyframes.sass +205 -0
- data/app/assets/stylesheets/thesis/base/bourbon/_bourbon-deprecated-upcoming.scss +8 -0
- data/app/assets/stylesheets/thesis/base/bourbon/_bourbon.scss +79 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_button.scss +374 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_clearfix.scss +23 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_directional-values.scss +111 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_ellipsis.scss +7 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_font-family.scss +5 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_hide-text.scss +10 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_html5-input-types.scss +86 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_position.scss +32 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_prefixer.scss +45 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_retina-image.scss +31 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_size.scss +16 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_timing-functions.scss +32 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_triangle.scss +83 -0
- data/app/assets/stylesheets/thesis/base/bourbon/addons/_word-wrap.scss +8 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_animation.scss +52 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_appearance.scss +3 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_backface-visibility.scss +6 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_background-image.scss +42 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_background.scss +55 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_border-image.scss +59 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_border-radius.scss +22 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_box-sizing.scss +4 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_calc.scss +4 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_columns.scss +47 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_filter.scss +5 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_flex-box.scss +321 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_font-face.scss +23 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_font-feature-settings.scss +10 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_hidpi-media-query.scss +10 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_hyphens.scss +4 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_image-rendering.scss +14 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_keyframes.scss +35 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_linear-gradient.scss +38 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_perspective.scss +8 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_placeholder.scss +8 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_radial-gradient.scss +39 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_transform.scss +15 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_transition.scss +77 -0
- data/app/assets/stylesheets/thesis/base/bourbon/css3/_user-select.scss +3 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_assign.scss +11 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_color-lightness.scss +13 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_flex-grid.scss +39 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_golden-ratio.scss +3 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_grid-width.scss +13 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_modular-scale.scss +66 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_px-to-em.scss +13 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_px-to-rem.scss +15 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_strip-units.scss +5 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_tint-shade.scss +9 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_transition-property-name.scss +22 -0
- data/app/assets/stylesheets/thesis/base/bourbon/functions/_unpack.scss +17 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_convert-units.scss +15 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_gradient-positions-parser.scss +13 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_is-num.scss +8 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_linear-angle-parser.scss +25 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_linear-gradient-parser.scss +41 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_linear-positions-parser.scss +61 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_linear-side-corner-parser.scss +31 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_radial-arg-parser.scss +69 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_radial-gradient-parser.scss +50 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_radial-positions-parser.scss +18 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_render-gradients.scss +26 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_shape-size-stripper.scss +10 -0
- data/app/assets/stylesheets/thesis/base/bourbon/helpers/_str-to-num.scss +50 -0
- data/app/assets/stylesheets/thesis/base/bourbon/settings/_asset-pipeline.scss +1 -0
- data/app/assets/stylesheets/thesis/base/bourbon/settings/_prefixer.scss +6 -0
- data/app/assets/stylesheets/thesis/base/bourbon/settings/_px-to-em.scss +1 -0
- data/lib/generators/thesis/install/install_generator.rb +21 -13
- data/lib/thesis/controllers/controller_helpers.rb +11 -5
- data/lib/thesis/controllers/thesis_controller.rb +16 -13
- data/lib/thesis/models/page.rb +29 -22
- data/lib/thesis/models/page_content.rb +44 -29
- data/lib/thesis/routing/route_constraint.rb +8 -2
- data/lib/thesis/routing/routes.rb +2 -3
- data/lib/thesis/version.rb +1 -1
- data/spec/factories/pages.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/{lib/thesis → thesis}/controllers/thesis_controller_spec.rb +15 -13
- data/spec/{lib/thesis → thesis}/models/page_content_spec.rb +4 -4
- data/spec/{lib/thesis → thesis}/models/page_spec.rb +0 -0
- data/spec/thesis/routing/thesis_routing_spec.rb +23 -0
- metadata +137 -56
- data/app/assets/javascripts/thesis/thesis.js.coffee +0 -157
- data/app/assets/stylesheets/thesis.css +0 -4
- data/app/assets/stylesheets/thesis/font-awesome/font-awesome.scss +0 -534
- data/app/assets/stylesheets/thesis/font/FontAwesome.otf +0 -0
- data/app/assets/stylesheets/thesis/font/fontawesome-webfont.eot +0 -0
- data/app/assets/stylesheets/thesis/font/fontawesome-webfont.svg +0 -284
- data/app/assets/stylesheets/thesis/font/fontawesome-webfont.ttf +0 -0
- data/app/assets/stylesheets/thesis/font/fontawesome-webfont.woff +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/animated-overlay.gif +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_flat_30_cccccc_40x100.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_flat_50_5c5c5c_40x100.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_glass_20_555555_1x400.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_glass_40_0078a3_1x400.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_glass_40_ffc73d_1x400.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_gloss-wave_25_333333_500x100.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_highlight-soft_80_eeeeee_1x100.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_inset-soft_25_000000_1x100.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-bg_inset-soft_30_f58400_1x100.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-icons_4b8e0b_256x240.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-icons_a83300_256x240.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-icons_cccccc_256x240.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
- data/app/assets/stylesheets/thesis/jquery-ui/jquery-ui-1.10.2.custom.css +0 -1175
- data/app/assets/stylesheets/thesis/thesis.css.scss +0 -65
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
@function _shape-size-stripper($shape-size) {
|
|
2
|
+
$shape-size-spec: null;
|
|
3
|
+
@each $value in $shape-size {
|
|
4
|
+
@if ($value == "cover") or ($value == "contain") {
|
|
5
|
+
$value: null;
|
|
6
|
+
}
|
|
7
|
+
$shape-size-spec: "#{$shape-size-spec} #{$value}";
|
|
8
|
+
}
|
|
9
|
+
@return $shape-size-spec;
|
|
10
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//************************************************************************//
|
|
2
|
+
// Helper function for linear/radial-gradient-parsers.
|
|
3
|
+
// Source: http://sassmeister.com/gist/9647408
|
|
4
|
+
//************************************************************************//
|
|
5
|
+
@function _str-to-num($string) {
|
|
6
|
+
// Matrices
|
|
7
|
+
$strings: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
|
|
8
|
+
$numbers: 0 1 2 3 4 5 6 7 8 9;
|
|
9
|
+
|
|
10
|
+
// Result
|
|
11
|
+
$result: 0;
|
|
12
|
+
$divider: 0;
|
|
13
|
+
$minus: false;
|
|
14
|
+
|
|
15
|
+
// Looping through all characters
|
|
16
|
+
@for $i from 1 through str-length($string) {
|
|
17
|
+
$character: str-slice($string, $i, $i);
|
|
18
|
+
$index: index($strings, $character);
|
|
19
|
+
|
|
20
|
+
@if $character == '-' {
|
|
21
|
+
$minus: true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@else if $character == '.' {
|
|
25
|
+
$divider: 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@else {
|
|
29
|
+
@if not $index {
|
|
30
|
+
$result: if($minus, $result * -1, $result);
|
|
31
|
+
@return _convert-units($result, str-slice($string, $i));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
$number: nth($numbers, $index);
|
|
35
|
+
|
|
36
|
+
@if $divider == 0 {
|
|
37
|
+
$result: $result * 10;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@else {
|
|
41
|
+
// Move the decimal dot to the left
|
|
42
|
+
$divider: $divider * 10;
|
|
43
|
+
$number: $number / $divider;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
$result: $result + $number;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
@return if($minus, $result * -1, $result);
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$asset-pipeline: false !default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$em-base: 16px !default;
|
|
@@ -4,11 +4,11 @@ module Thesis
|
|
|
4
4
|
module Generators
|
|
5
5
|
class InstallGenerator < ::Rails::Generators::Base
|
|
6
6
|
include Rails::Generators::Migration
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
desc "install or upgrade Thesis"
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
def self.next_migration_number(path)
|
|
13
13
|
unless @prev_migration_nr
|
|
14
14
|
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
|
@@ -19,20 +19,20 @@ module Thesis
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def copy_migrations
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
copy_migration "thesis_create_page"
|
|
23
|
+
copy_migration "thesis_create_page_content"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def create_folders
|
|
27
|
-
copy_file "page_templates/default.html.slim", "app/views/page_templates/default.html.slim" if defined? Slim
|
|
28
|
-
copy_file "page_templates/default.html.haml", "app/views/page_templates/default.html.haml" if defined? Haml
|
|
29
|
-
copy_file "page_templates/default.html.erb", "app/views/page_templates/default.html.erb"
|
|
27
|
+
return copy_file "page_templates/default.html.slim", "app/views/page_templates/default.html.slim" if defined? Slim
|
|
28
|
+
return copy_file "page_templates/default.html.haml", "app/views/page_templates/default.html.haml" if defined? Haml
|
|
29
|
+
copy_file "page_templates/default.html.erb", "app/views/page_templates/default.html.erb"
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def install_js
|
|
33
33
|
filename = "app/assets/javascripts/application.js"
|
|
34
34
|
existing = File.binread("#{filename}").include?("require thesis")
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
if existing && generating?
|
|
37
37
|
say_status("skipped", "insert into #{filename}", :yellow)
|
|
38
38
|
else
|
|
@@ -48,7 +48,7 @@ module Thesis
|
|
|
48
48
|
filename = filename << ".scss" unless File.exists? filename
|
|
49
49
|
if File.exists? filename
|
|
50
50
|
existing = File.binread("#{filename}").include?("require thesis")
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
if existing && generating?
|
|
53
53
|
say_status("skipped", "insert into #{filename}", :yellow)
|
|
54
54
|
else
|
|
@@ -64,11 +64,11 @@ module Thesis
|
|
|
64
64
|
def install_page_is_editable
|
|
65
65
|
filename = "app/controllers/application_controller.rb"
|
|
66
66
|
existing = File.binread("#{filename}").include?("def page_is_editable?")
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
if existing && generating?
|
|
69
69
|
say_status("skipped", "insert into #{filename}", :yellow)
|
|
70
70
|
else
|
|
71
|
-
insert_into_file "#{filename}", after: %r{ protect_from_forgery} do
|
|
71
|
+
insert_into_file "#{filename}", after: %r{ protect_from_forgery with: :exception} do
|
|
72
72
|
"\n" +
|
|
73
73
|
"\n # Thesis authentication" +
|
|
74
74
|
"\n def page_is_editable?(page)" +
|
|
@@ -103,7 +103,15 @@ module Thesis
|
|
|
103
103
|
|
|
104
104
|
def destroying?
|
|
105
105
|
:revoke == behavior
|
|
106
|
-
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def copy_migration(filename)
|
|
109
|
+
if generating? && self.class.migration_exists?("db/migrate", "#{filename}")
|
|
110
|
+
say_status("skipped", "Migration #{filename}.rb already exists")
|
|
111
|
+
else
|
|
112
|
+
migration_template "migrations/#{filename}.rb", "db/migrate/#{filename}.rb"
|
|
113
|
+
end
|
|
114
|
+
end
|
|
107
115
|
end
|
|
108
116
|
end
|
|
109
117
|
end
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
module Thesis
|
|
2
2
|
module ControllerHelpers
|
|
3
3
|
def current_page
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
@current_page ||= begin
|
|
5
|
+
p = Page.where(slug: current_slug).first_or_create
|
|
6
|
+
p.editable = page_is_editable?(p)
|
|
7
|
+
p
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def current_slug
|
|
12
|
+
request.fullpath.sub(/(\/)+$/,'').presence || "/"
|
|
7
13
|
end
|
|
8
14
|
|
|
9
15
|
def root_pages
|
|
10
16
|
@root_pages ||= Page.where(parent_id: nil).order("sort_order ASC")
|
|
11
17
|
end
|
|
12
|
-
|
|
18
|
+
|
|
13
19
|
def thesis_editor
|
|
14
|
-
"<div id='thesis-editor'></div>".html_safe
|
|
20
|
+
current_page.editable ? "<div id='thesis-editor'></div>".html_safe : ""
|
|
15
21
|
end
|
|
16
22
|
end
|
|
17
23
|
end
|
|
@@ -4,15 +4,17 @@ module Thesis
|
|
|
4
4
|
|
|
5
5
|
def show
|
|
6
6
|
raise ActionController::RoutingError.new('Not Found') unless current_page
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
if current_page.template && template_exists?("page_templates/#{current_page.template}")
|
|
9
9
|
render "page_templates/#{current_page.template}", layout: false
|
|
10
|
+
elsif template_exists?("page_templates/default")
|
|
11
|
+
render "page_templates/default"
|
|
10
12
|
else
|
|
11
|
-
raise PageRequiresTemplate.new("
|
|
13
|
+
raise PageRequiresTemplate.new("No default template found in page_templates. Create page_templates/default.html.(erb|haml|slim).")
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
|
-
|
|
15
|
-
def create_page
|
|
16
|
+
|
|
17
|
+
def create_page
|
|
16
18
|
page = Page.new
|
|
17
19
|
return head :forbidden unless page_is_editable?(page)
|
|
18
20
|
|
|
@@ -23,8 +25,9 @@ module Thesis
|
|
|
23
25
|
page.parent = parent
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
resp = {}
|
|
28
|
+
resp = { page: page }
|
|
27
29
|
|
|
30
|
+
page.update_slug
|
|
28
31
|
if page.save
|
|
29
32
|
resp[:page] = page
|
|
30
33
|
else
|
|
@@ -33,30 +36,30 @@ module Thesis
|
|
|
33
36
|
|
|
34
37
|
render json: resp, status: page.valid? ? :ok : :not_acceptable
|
|
35
38
|
end
|
|
36
|
-
|
|
37
|
-
def delete_page
|
|
39
|
+
|
|
40
|
+
def delete_page
|
|
38
41
|
slug = params[:slug].to_s.sub(/(\/)+$/,'')
|
|
39
42
|
page = Page.where(slug: slug).first
|
|
40
43
|
return head :forbidden unless page && page_is_editable?(page)
|
|
41
44
|
|
|
42
45
|
head page.destroy ? :ok : :not_acceptable
|
|
43
46
|
end
|
|
44
|
-
|
|
47
|
+
|
|
45
48
|
def update_page
|
|
46
49
|
page = current_page
|
|
47
50
|
return head :forbidden unless page_is_editable?(page)
|
|
48
51
|
|
|
49
52
|
update_page_attributes page
|
|
50
|
-
|
|
53
|
+
|
|
51
54
|
head page.save ? :ok : :not_acceptable
|
|
52
55
|
end
|
|
53
56
|
|
|
54
57
|
def page_attributes
|
|
55
58
|
[ :name, :title, :description, :parent_id ]
|
|
56
59
|
end
|
|
57
|
-
|
|
60
|
+
|
|
58
61
|
def update_page_attributes(page)
|
|
59
|
-
page_attributes.each { |a| page.send("#{a}=", params[a]) if params[a] }
|
|
62
|
+
page_attributes.each { |a| page.send("#{a}=", params[a].to_s) if params[a] }
|
|
60
63
|
page
|
|
61
64
|
end
|
|
62
65
|
|
|
@@ -71,7 +74,7 @@ module Thesis
|
|
|
71
74
|
else
|
|
72
75
|
page_contents.each do |pc|
|
|
73
76
|
if page_is_editable? pc.page
|
|
74
|
-
pc.content = params[pc.id.to_s]
|
|
77
|
+
pc.content = params[pc.id.to_s].to_s.presence || " ".html_safe
|
|
75
78
|
pc.save
|
|
76
79
|
else
|
|
77
80
|
errors = true
|
|
@@ -85,7 +88,7 @@ module Thesis
|
|
|
85
88
|
|
|
86
89
|
render json: resp, status: errors ? :not_acceptable : :ok
|
|
87
90
|
end
|
|
88
|
-
|
|
91
|
+
|
|
89
92
|
# The ApplicationController should implement this.
|
|
90
93
|
def page_is_editable?(page)
|
|
91
94
|
raise RequiredMethodNotImplemented.new("Add a `page_is_editable?(page)` method to your controller that returns true or false.") unless defined?(super)
|
data/lib/thesis/models/page.rb
CHANGED
|
@@ -1,47 +1,54 @@
|
|
|
1
1
|
module Thesis
|
|
2
2
|
class Page < ActiveRecord::Base
|
|
3
|
+
attr_accessor :editable
|
|
4
|
+
|
|
3
5
|
self.table_name = "pages"
|
|
4
|
-
|
|
6
|
+
|
|
5
7
|
belongs_to :parent, class_name: "Page"
|
|
6
|
-
has_many :subpages, class_name: "Page", foreign_key: "parent_id"
|
|
8
|
+
has_many :subpages, -> { order(:sort_order) }, class_name: "Page", foreign_key: "parent_id"
|
|
7
9
|
has_many :page_contents, dependent: :destroy
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
before_create :set_name
|
|
12
|
+
before_save :update_slug # Do we even want to do this?
|
|
10
13
|
after_save :update_subpage_slugs
|
|
11
|
-
|
|
12
|
-
validates :slug,
|
|
13
|
-
uniqueness: { message: "There's already a page
|
|
14
|
+
|
|
15
|
+
validates :slug,
|
|
16
|
+
uniqueness: { message: "There's already a page at that location." },
|
|
14
17
|
presence: true,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
allow_blank: true,
|
|
19
|
+
allow_null: false
|
|
20
|
+
|
|
21
|
+
def set_name
|
|
22
|
+
self.name ||= self.slug.to_s.split("/").last.to_s.humanize if self.slug
|
|
23
|
+
end
|
|
24
|
+
|
|
18
25
|
def update_slug
|
|
26
|
+
self.name ||= ""
|
|
19
27
|
self.slug = "/" << self.name.parameterize
|
|
20
28
|
self.slug = "#{parent.slug.to_s}#{self.slug.to_s}" if parent
|
|
21
29
|
end
|
|
22
|
-
|
|
30
|
+
|
|
23
31
|
def update_subpage_slugs
|
|
24
32
|
subpages.each(&:save) if slug_changed?
|
|
25
33
|
end
|
|
26
|
-
|
|
34
|
+
|
|
27
35
|
def content(name, content_type = :html, opts = {})
|
|
28
|
-
|
|
29
|
-
pc.render
|
|
36
|
+
find_or_create_page_content(name, content_type, opts).render(editable: self.editable)
|
|
30
37
|
end
|
|
31
|
-
|
|
38
|
+
|
|
32
39
|
def path
|
|
33
40
|
self.slug
|
|
34
41
|
end
|
|
35
|
-
|
|
42
|
+
|
|
36
43
|
protected
|
|
37
|
-
|
|
44
|
+
|
|
38
45
|
def find_or_create_page_content(name, content_type, opts = {})
|
|
39
|
-
page_content =
|
|
40
|
-
pc.content =
|
|
41
|
-
pc.content =
|
|
42
|
-
width =
|
|
43
|
-
height =
|
|
44
|
-
pc.content =
|
|
46
|
+
page_content = self.page_contents.where(name: name).first_or_create do |pc|
|
|
47
|
+
pc.content = opts[:default] || "<p>Edit This HTML Area</p>" if content_type == :html
|
|
48
|
+
pc.content = opts[:default] || "Edit This Text Area" if content_type == :text
|
|
49
|
+
width = opts[:width] || 350
|
|
50
|
+
height = opts[:height] || 150
|
|
51
|
+
pc.content = opts[:default] || "http://placehold.it/#{width}x#{height}" if content_type == :image
|
|
45
52
|
end
|
|
46
53
|
page_content.content_type = content_type
|
|
47
54
|
page_content.save if page_content.changed?
|
|
@@ -3,41 +3,56 @@ module Thesis
|
|
|
3
3
|
self.table_name = "page_contents"
|
|
4
4
|
|
|
5
5
|
belongs_to :page
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
validates :page_id, presence: true
|
|
7
|
+
|
|
8
|
+
def render(args={})
|
|
9
|
+
args[:editable] ? render_editable : render_content
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def render_editable
|
|
13
|
+
case self.content_type.to_sym
|
|
14
|
+
when :html then render_html_editable
|
|
15
|
+
when :text then render_plain_text_editable
|
|
16
|
+
when :image then render_image_editable
|
|
17
|
+
else render_html_editable
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def render_content
|
|
8
22
|
case self.content_type.to_sym
|
|
9
|
-
when :
|
|
10
|
-
|
|
11
|
-
when :text
|
|
12
|
-
render_plain_text
|
|
13
|
-
when :image
|
|
14
|
-
render_image
|
|
15
|
-
else
|
|
16
|
-
render_html
|
|
23
|
+
when :image then render_image_tag
|
|
24
|
+
else self.content.to_s.html_safe
|
|
17
25
|
end
|
|
18
26
|
end
|
|
19
|
-
|
|
27
|
+
|
|
20
28
|
protected
|
|
21
|
-
|
|
22
|
-
def
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
29
|
+
|
|
30
|
+
def render_html_editable
|
|
31
|
+
(
|
|
32
|
+
"<thesis-content class='thesis-content thesis-content-html' data-thesis-content-id='#{self.id}'>" +
|
|
33
|
+
"#{self.content}" +
|
|
34
|
+
"</thesis-content>"
|
|
35
|
+
).html_safe
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def render_plain_text_editable
|
|
39
|
+
(
|
|
40
|
+
"<thesis-content class='thesis-content thesis-content-text' data-thesis-content-id='#{self.id}'>" +
|
|
41
|
+
"#{self.content}" +
|
|
42
|
+
"</thesis-content>"
|
|
43
|
+
).html_safe
|
|
27
44
|
end
|
|
28
|
-
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
|
|
46
|
+
def render_image_editable
|
|
47
|
+
(
|
|
48
|
+
"<thesis-content class='thesis-content thesis-content-image' data-thesis-content-id='#{self.id}'>" +
|
|
49
|
+
render_image_tag +
|
|
50
|
+
"</thesis-content>"
|
|
51
|
+
).html_safe
|
|
34
52
|
end
|
|
35
|
-
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
"<img src='#{self.content}' />" +
|
|
39
|
-
"</div>"
|
|
40
|
-
h.html_safe
|
|
53
|
+
|
|
54
|
+
def render_image_tag
|
|
55
|
+
"<img src='#{self.content}' />".html_safe
|
|
41
56
|
end
|
|
42
57
|
end
|
|
43
58
|
end
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
module Thesis
|
|
2
2
|
class RouteConstraint
|
|
3
|
-
def
|
|
3
|
+
def matches?(request)
|
|
4
4
|
slug = request.path.to_s.sub(/(\/)+$/,'')
|
|
5
|
-
|
|
5
|
+
return false if excluded_path?(slug)
|
|
6
|
+
Page.where(slug: slug).size > 0
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def excluded_path?(path)
|
|
10
|
+
excluded_extensions = [ :jpg, :jpeg, :png, :css, :js, :ico, :pdf ]
|
|
11
|
+
excluded_extensions.any?{ |ext| path.ends_with?(".#{ext}") }
|
|
6
12
|
end
|
|
7
13
|
end
|
|
8
14
|
end
|