ecrire 0.31.1 → 0.31.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/Gemfile +2 -1
  4. data/Rakefile +1 -45
  5. data/lib/ecrire.rb +12 -0
  6. data/lib/ecrire/app/assets/javascripts/admin/posts/content.coffee +7 -7
  7. data/lib/ecrire/app/assets/javascripts/admin/posts/header.coffee +1 -1
  8. data/lib/ecrire/app/assets/stylesheets/admin/base.scss +12 -3
  9. data/lib/ecrire/app/assets/stylesheets/admin/navigation.scss +0 -31
  10. data/lib/ecrire/app/assets/stylesheets/admin/navigation/base.scss +30 -0
  11. data/lib/ecrire/app/assets/stylesheets/admin/navigation/home.scss +22 -0
  12. data/lib/ecrire/app/assets/stylesheets/admin/posts.scss +0 -50
  13. data/lib/ecrire/app/assets/stylesheets/admin/posts/aside.scss +36 -0
  14. data/lib/ecrire/app/assets/stylesheets/admin/posts/editor.scss +4 -0
  15. data/lib/ecrire/app/assets/stylesheets/admin/posts/header.scss +2 -1
  16. data/lib/ecrire/app/assets/stylesheets/admin/posts/list.scss +61 -0
  17. data/lib/ecrire/app/assets/stylesheets/admin/{preview.scss → posts/preview.scss} +6 -3
  18. data/lib/ecrire/app/assets/stylesheets/editor/blockquote.scss +4 -0
  19. data/lib/ecrire/app/assets/stylesheets/editor/code.scss +1 -0
  20. data/lib/ecrire/app/assets/stylesheets/editor/content.scss +1 -1
  21. data/lib/ecrire/app/assets/stylesheets/editor/html.scss +20 -0
  22. data/lib/ecrire/app/assets/stylesheets/variables.scss +3 -0
  23. data/lib/ecrire/app/controllers/admin/posts_controller.rb +4 -4
  24. data/lib/ecrire/app/helpers/admin/images_helper.rb +4 -4
  25. data/lib/ecrire/app/helpers/admin/posts_helper.rb +4 -4
  26. data/lib/ecrire/app/helpers/application_helper.rb +1 -1
  27. data/lib/ecrire/app/models/admin/image.rb +4 -4
  28. data/lib/ecrire/app/models/post.rb +1 -1
  29. data/lib/ecrire/app/models/user.rb +4 -0
  30. data/lib/ecrire/app/views/admin/posts/_search.html.erb +1 -8
  31. data/lib/ecrire/app/views/admin/posts/help.js.erb +1 -1
  32. data/lib/ecrire/app/views/admin/posts/index.html.erb +43 -20
  33. data/lib/ecrire/app/views/admin/posts/index.js.erb +1 -1
  34. data/lib/ecrire/app/views/admin/posts/show.html.erb +2 -2
  35. data/lib/ecrire/app/views/admin/posts/tags/create.js.erb +2 -2
  36. data/lib/ecrire/app/views/admin/posts/tags/index.js.erb +1 -1
  37. data/lib/ecrire/app/views/admin/posts/tags/toggle.js.erb +2 -2
  38. data/lib/ecrire/app/views/admin/posts/titles/create.js.erb +2 -2
  39. data/lib/ecrire/app/views/admin/posts/titles/index.js.erb +1 -1
  40. data/lib/ecrire/app/views/admin/posts/titles/update.js.erb +1 -1
  41. data/lib/ecrire/app/views/admin/profiles/show.js.erb +1 -1
  42. data/lib/ecrire/app/views/admin/tags/create.js.erb +1 -1
  43. data/lib/ecrire/app/views/admin/tags/index.js.erb +1 -1
  44. data/lib/ecrire/app/views/admin/tags/update.js.erb +1 -1
  45. data/lib/ecrire/app/views/admin/titles/edit.js.erb +1 -1
  46. data/lib/ecrire/app/views/admin/titles/errors.js.erb +1 -1
  47. data/lib/ecrire/app/views/admin/titles/index.js.erb +1 -1
  48. data/lib/ecrire/app/views/layouts/admin/application.html.erb +20 -2
  49. data/lib/ecrire/application.rb +53 -29
  50. data/lib/ecrire/commands/server.rb +12 -2
  51. data/lib/ecrire/configuration.rb +39 -0
  52. data/lib/ecrire/onboarding/controllers/onboarding_controller.rb +2 -0
  53. data/lib/ecrire/onboarding/engine.rb +0 -4
  54. data/lib/ecrire/theme/engine.rb +4 -4
  55. data/lib/ecrire/theme/template/Gemfile +16 -16
  56. data/lib/ecrire/version.rb +1 -1
  57. data/test/configuration/postgresql.rb +60 -11
  58. data/test/editor/initializers.rb +20 -13
  59. data/test/editor/models/image_test.rb +2 -2
  60. data/test/editor/theme/secrets.yml +9 -0
  61. data/test/onboarding/initializers.rb +0 -2
  62. data/test/onboarding/theme/config.ru +0 -0
  63. data/test/task.rb +32 -24
  64. data/test/theme/initializers.rb +17 -12
  65. data/test/{secrets.yml → theme/theme/secrets.yml} +2 -0
  66. metadata +14 -4
@@ -1,10 +1,10 @@
1
- #PostPreviewContent > article {
1
+ #PostPreview > article {
2
2
  @include justify-content(flex-start);
3
3
 
4
4
  max-width: 900px;
5
5
  margin: 0 auto;
6
6
  padding: 0 1em 6em 1em;
7
- width: 100%;
7
+ width: 100vw;
8
8
 
9
9
  font-size: 1.3em;
10
10
  line-height: 1.6em;
@@ -14,6 +14,7 @@
14
14
  }
15
15
 
16
16
  ul, ol {
17
+ margin: 1.5em 0;
17
18
  padding-left: 1em;
18
19
  }
19
20
 
@@ -27,6 +28,7 @@
27
28
 
28
29
  li {
29
30
  margin: 0.3em 0;
31
+ padding: 0;
30
32
  }
31
33
 
32
34
  p {
@@ -53,7 +55,7 @@
53
55
  }
54
56
 
55
57
 
56
- #PostPreviewContent pre {
58
+ #PostPreview pre {
57
59
  background-color: $light-blue;
58
60
  font-size: 0.7em;
59
61
  border-radius: 2px;
@@ -72,3 +74,4 @@
72
74
  display: inline-block;
73
75
  }
74
76
  }
77
+
@@ -0,0 +1,4 @@
1
+ blockquote {
2
+ background: $light-blue;
3
+ padding: 4px 24px;
4
+ }
@@ -10,6 +10,7 @@ article.content pre {
10
10
  background: lighten($light-blue, 5%);
11
11
  border-top: 1px solid $light-blue;
12
12
  padding: 0.7em;
13
+ line-height: 1.1em;
13
14
  }
14
15
 
15
16
  article.content pre > code {
@@ -4,7 +4,7 @@ article.content {
4
4
  font-weight: 200;
5
5
  outline: none;
6
6
  font-size: 1.3em;
7
- max-width: calc(800px + 4em);
7
+ max-width: calc(900px + 4em);
8
8
  width: 100%;
9
9
  margin: 0 auto;
10
10
  padding: 0 2em;
@@ -0,0 +1,20 @@
1
+ article.content div {
2
+ padding: 0.2rem 0.8rem;
3
+ border-left: solid 3px $light-blue;
4
+ font-size: 0.8rem;
5
+ position: relative;
6
+ }
7
+
8
+ article.content div:before {
9
+ content: 'HTML';
10
+ position: absolute;
11
+ left: -1.3rem;
12
+ top: 0;
13
+ bottom: 0;
14
+ width: 1rem;
15
+ font-size: 1.2rem;
16
+ font-weight: bold;
17
+ break-word: break-all;
18
+ color: $light-blue;
19
+ overflow-y: hidden;
20
+ }
@@ -8,7 +8,10 @@ $red: rgb(169, 40, 40);
8
8
  $light-blue: rgb(202, 217, 231);
9
9
  $bright-blue: rgb(41, 131, 195);
10
10
  $navy-blue: #324D66;
11
+
11
12
  $gray-blue: #85919D;
13
+ $gray: #CCC;
14
+ $light-gray: #e4e4e4;
12
15
 
13
16
  $green: rgb(92, 184, 92);
14
17
 
@@ -20,19 +20,19 @@ module Admin
20
20
  end
21
21
 
22
22
  def drafts
23
- posts = Admin::Post.drafted
23
+ posts = Admin::Post
24
24
 
25
25
  posts = posts.search search_posts_params
26
- @posts = posts.order('posts.created_at DESC').includes(:titles)
26
+ @posts = posts.drafted.order('posts.created_at DESC').includes(:titles)
27
27
 
28
28
  render 'index'
29
29
  end
30
30
 
31
31
  def published
32
- posts = Admin::Post.published
32
+ posts = Admin::Post
33
33
 
34
34
  posts = posts.search search_posts_params
35
- @posts = posts.order('posts.published_at DESC').includes(:titles)
35
+ @posts = posts.published.order('posts.published_at DESC').includes(:titles)
36
36
  render 'index'
37
37
  end
38
38
 
@@ -3,7 +3,7 @@ module Admin
3
3
 
4
4
  def image_form_signature(policy)
5
5
  @signature ||= begin
6
- key = Rails.application.secrets.s3['secret_key']
6
+ key = Rails.application.secrets.s3[:secret_key]
7
7
  sha = OpenSSL::Digest.new('sha1')
8
8
  digest = OpenSSL::HMAC.digest sha, key, policy
9
9
  Base64.encode64(digest).gsub("\n", "")
@@ -13,14 +13,14 @@ module Admin
13
13
  def image_form_policy(post)
14
14
  @policy ||= begin
15
15
  namespace = [post.id]
16
- if Rails.application.secrets.s3.has_key?('namespace')
17
- namespace.insert 0, Rails.application.secrets.s3['namespace']
16
+ if Rails.application.secrets.s3.has_key?(:namespace)
17
+ namespace.insert 0, Rails.application.secrets.s3[:namespace]
18
18
  end
19
19
 
20
20
  policy = {
21
21
  "expiration" => (Time.now + 10.years).utc.to_s(:iso8601),
22
22
  "conditions" => [
23
- {"bucket" => Rails.application.secrets.s3['bucket']},
23
+ {"bucket" => Rails.application.secrets.s3[:bucket]},
24
24
  ["starts-with", "$key", "#{namespace.join('/')}/"],
25
25
  ["starts-with", "$Content-Type", ""],
26
26
  {"acl" => "private"}
@@ -19,12 +19,12 @@ module Admin
19
19
  contenteditable: true,
20
20
  href: admin_post_path(@post.id) do |div|
21
21
 
22
- namespace = Pathname.new(Rails.application.secrets.s3['namespace'] || '')
22
+ namespace = Pathname.new(Rails.application.secrets.fetch(:s3, {})['namespace'] || '')
23
23
 
24
24
  if Rails.application.secrets.has_key?(:s3)
25
- div['data-bucket'] = Rails.application.secrets.s3['bucket']
26
- div['data-url'] = Rails.application.secrets.s3['url']
27
- div['data-access-key'] = Rails.application.secrets.s3['access_key']
25
+ div['data-bucket'] = Rails.application.secrets.s3[:bucket]
26
+ div['data-url'] = Rails.application.secrets.s3[:url]
27
+ div['data-access-key'] = Rails.application.secrets.s3[:access_key]
28
28
  div['data-signature'] = image_form_signature(image_form_policy(@post))
29
29
  div['data-policy'] = image_form_policy(@post)
30
30
  div['data-namespace'] = namespace + @post.id.to_s
@@ -43,7 +43,7 @@ module ApplicationHelper
43
43
  # Will generate the asset url given with the +name+ of your favicon.
44
44
  #
45
45
  def favicon_tag(name = 'favicon.ico')
46
- content_tag :link, nil, rel: %w(shortcut icon), href: asset_url(name)
46
+ content_tag :link, nil, rel: %w(shortcut icon), href: image_path(name)
47
47
  end
48
48
 
49
49
  ##
@@ -56,11 +56,11 @@ module Admin
56
56
 
57
57
  def initialize(options={})
58
58
  @errors = ActiveModel::Errors.new(self)
59
- @access_key = options.fetch('access_key', "")
60
- @secret_key = options.fetch('secret_key', "")
61
- @path = options.fetch('path', "")
59
+ @access_key = options.fetch(:access_key, "")
60
+ @secret_key = options.fetch(:secret_key, "")
61
+ @path = options.fetch(:path, "")
62
62
 
63
- @bucket = service.bucket(options.fetch('bucket', 'ecrire'))
63
+ @bucket = service.bucket(options.fetch(:bucket, 'ecrire'))
64
64
  end
65
65
 
66
66
  def configuration_hash
@@ -131,7 +131,7 @@ class Post < ActiveRecord::Base
131
131
  def content
132
132
  @content ||= begin
133
133
  content = read_attribute('content')
134
- Content.new(content.fetch('raw', ''), content.fetch('html', ''))
134
+ Content.new(content.fetch('raw', ''), content.fetch('html', '').html_safe)
135
135
  end
136
136
  end
137
137
 
@@ -13,6 +13,10 @@ class User < ActiveRecord::Base
13
13
 
14
14
  validates_confirmation_of :password, if: ->{ password.present? }
15
15
 
16
+ def display_name
17
+ self.email
18
+ end
19
+
16
20
  def password
17
21
  return if self.encrypted_password.blank?
18
22
  @password ||= Password.new(self.encrypted_password)
@@ -19,14 +19,7 @@
19
19
  <% input[:name] = 'posts[title]' %>
20
20
  <% input[:class] << 'search' %>
21
21
  <% input[:form] = 'PostsFilter' %>
22
-
23
- <% if search_posts_params[:status] == 'draft' %>
24
- <% input[:placeholder] = 'Search for a draft' %>
25
- <% elsif search_posts_params[:status] == 'published' %>
26
- <% input[:placeholder] = 'Search for a published post' %>
27
- <% else %>
28
- <% input[:placeholder] = 'Search for any post' %>
29
- <% end %>
22
+ <% input[:placeholder] = 'Search' %>
30
23
 
31
24
  <% end %>
32
25
 
@@ -1 +1 @@
1
- e.HTML = "<%= j render('documentation') %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render('documentation') %>")
@@ -1,25 +1,48 @@
1
- <% content_for 'Navigation::Posts' do %>
2
-
3
- <%= content_tag :a, href: drafts_admin_posts_path do |a| %>
4
- <% if action_name.eql?('drafts') %>
5
- <% a.css << 'selected' %>
6
- <% end %>
7
- Drafts
8
- <% end %>
9
-
10
- <%= content_tag :a, href: published_admin_posts_path do |a| %>
11
- <% if action_name.eql?('published') %>
12
- <% a.css << 'selected' %>
13
- <% end %>
14
- Published
15
- <% end %>
16
-
17
- <%= link_to 'New Post', new_admin_post_path %>
18
- <% end %>
19
-
20
- <%= render('admin/navigation') %>
1
+ <% content_for 'Content::Style', 'split' %>
2
+ <% content_for 'Content::Class', 'list' %>
3
+
4
+ <aside>
5
+ <%= link_to 'New Post', new_admin_post_path, class: %w(button new) %>
6
+
7
+ <ol>
8
+ <li>
9
+ <%= content_tag :a, href: admin_posts_path do |a| %>
10
+ <% if action_name.eql?('index') %>
11
+ <% a.css << 'selected' %>
12
+ <% end %>
13
+ All
14
+ <% end %>
15
+ </li>
16
+
17
+ <li>
18
+ <%= content_tag :a, href: drafts_admin_posts_path do |a| %>
19
+ <% if action_name.eql?('drafts') %>
20
+ <% a.css << 'selected' %>
21
+ <% end %>
22
+ Drafts
23
+ <% end %>
24
+ </li>
25
+
26
+ <li>
27
+ <%= content_tag :a, href: published_admin_posts_path do |a| %>
28
+ <% if action_name.eql?('published') %>
29
+ <% a.css << 'selected' %>
30
+ <% end %>
31
+ Published
32
+ <% end %>
33
+ </li>
34
+ </ol>
35
+
36
+ </aside>
21
37
 
22
38
  <section id='PostsIndexList' class='posts'>
39
+ <% if action_name.eql?('drafts') %>
40
+ <h2>Draft Posts</h2>
41
+ <% elsif action_name.eql?('published') %>
42
+ <h2>Published Posts</h2>
43
+ <% else %>
44
+ <h2>All Posts</h2>
45
+ <% end %>
23
46
 
24
47
  <%= form_for :posts, url: {controller: 'admin/posts', action: action_name}, method: 'GET', html: {class: %w(search), name: 'posts', id: 'PostsFilter', as: 'Posts.Filter'} do |f| %>
25
48
  <%= render('search') %>
@@ -1 +1 @@
1
- e.HTML = "<%= j content_tag(:ul, render(@posts)) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j content_tag(:ul, render(@posts)) %>")
@@ -8,6 +8,6 @@
8
8
  <%= render 'admin/posts/header/base', post: @post %>
9
9
  <% end %>
10
10
 
11
- <section class='preview' id='PostPreviewContent'>
12
- <%= content_tag :article, @post.compiled_content.try(:html_safe) %>
11
+ <section id='PostPreview'>
12
+ <%= content_tag :article, @post.content.html %>
13
13
  <section>
@@ -1,2 +1,2 @@
1
- e.HTML = "<%= j render('admin/posts/tags/tag', tag: @tag, post: @post) %>".toHTML()
2
- e.TagsHTML = "<%= j post_tags(@post) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render('admin/posts/tags/tag', tag: @tag, post: @post) %>")
2
+ e.TagsHTML = ObserveJS.HTML.parse("<%= j post_tags(@post) %>")
@@ -1 +1 @@
1
- e.HTML = "<%= j popup_tag(render('admin/posts/tags/tags', post: @post, tags: @tags), class: %w(tags)) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j popup_tag(render('admin/posts/tags/tags', post: @post, tags: @tags), class: %w(tags)) %>")
@@ -1,2 +1,2 @@
1
- e.HTML = "<%= j render('admin/posts/tags/tag', tag: @tag, post: @post) %>".toHTML()
2
- e.TagsHTML = "<%= j post_tags(@post) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render('admin/posts/tags/tag', tag: @tag, post: @post) %>")
2
+ e.TagsHTML = ObserveJS.HTML.parse("<%= j post_tags(@post) %>")
@@ -1,6 +1,6 @@
1
1
  <% if @title.errors.any? %>
2
- e.ErrorHTML = "<%= j content_tag(:div, @title.errors.to_a.to_sentence, class: %w(errors)) %>".toHTML()
2
+ e.ErrorHTML = ObserveJS.HTML.parse("<%= j content_tag(:div, @title.errors.to_a.to_sentence, class: %w(errors)) %>")
3
3
  <% else %>
4
- e.HTML = "<%= j render('admin/posts/titles/title', title: @title) %>".toHTML()
4
+ e.HTML = ObserveJS.HTML.parse("<%= j render('admin/posts/titles/title', title: @title) %>")
5
5
  <% end %>
6
6
 
@@ -1,2 +1,2 @@
1
- e.HTML = "<%= j popup_tag(render('admin/posts/titles/form', post: @post, title: @title), class: %w(popup titles)) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j popup_tag(render('admin/posts/titles/form', post: @post, title: @title), class: %w(popup titles)) %>")
2
2
 
@@ -1 +1 @@
1
- e.HTML = "<%= j render('admin/posts/titles/title', title: @title) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render('admin/posts/titles/title', title: @title) %>")
@@ -1 +1 @@
1
- e.HTML = "<%= j render("menu") %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render("menu") %>")
@@ -1 +1 @@
1
- e.HTML = "<%= j render('admin/posts/tags/dialog/tag', tag: @tag, post: @post) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render('admin/posts/tags/dialog/tag', tag: @tag, post: @post) %>")
@@ -1 +1 @@
1
- e.HTML = "<%= j popup_tag(render('admin/tags/tags', tags: @tags), id: 'TagsPopup') %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j popup_tag(render('admin/tags/tags', tags: @tags), id: 'TagsPopup') %>")
@@ -1,2 +1,2 @@
1
1
  e.ObjectID = <%= @tag.id %>
2
- e.HTML = "<%= j render('admin/posts/tags/tag', post: @post, tag: @tag)%>".toHTML()
2
+ e.HTML = ObserveJS.HTML.parse("<%= j render('admin/posts/tags/tag', post: @post, tag: @tag)%>")
@@ -1 +1 @@
1
- e.HTML = "<%= j render('title', post: post) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render('title', post: post) %>")
@@ -1,5 +1,5 @@
1
1
  e.Errors = [
2
2
  <% @title.errors.each do |key, message| %>
3
- "<%= j content_tag(:li, message) %>".toHTML(),
3
+ ObserveJS.HTML.parse("<%= j content_tag(:li, message) %>"),
4
4
  <% end %>
5
5
  ]
@@ -1 +1 @@
1
- e.HTML = "<%= j render('titles', post: post) %>".toHTML()
1
+ e.HTML = ObserveJS.HTML.parse("<%= j render('titles', post: post) %>")
@@ -4,11 +4,29 @@
4
4
  <title>Ecrire</title>
5
5
  <link rel="shortcut icon" href="<%= image_url("favicon.ico")%>" />
6
6
  <%= stylesheet_link_tag "admin", media: "all" %>
7
- <%= javascript_include_tag "admin" %>
7
+ <%= javascript_include_tag "admin", 'data-turbolinks-track' => "reload" %>
8
8
  <%= csrf_meta_tags %>
9
9
  </head>
10
10
  <%= content_tag :body, class: [action_name, controller_name] do %>
11
- <%= main_tag do %>
11
+ <nav id='AdminNavigation'>
12
+ <%= link_to '/', class: %w(home) do %>
13
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Arrow_circled_left" x="0px" y="0px" viewBox="0 0 20 20" enable-background="new 0 0 20 20" xml:space="preserve">
14
+ <path d="M10,0.4c-5.303,0-9.601,4.298-9.601,9.6c0,5.303,4.298,9.601,9.601,9.601c5.301,0,9.6-4.298,9.6-9.601 C19.6,4.698,15.301,0.4,10,0.4z M9.999,17.6c-4.197,0-7.6-3.402-7.6-7.6s3.402-7.6,7.6-7.6S17.6,5.803,17.6,10 S14.196,17.6,9.999,17.6z M10,5.5L5.5,10l4.5,4.5V12h4V8h-4V5.5z"/>
15
+ </svg>
16
+ Back to your blog
17
+ <% end %>
18
+
19
+ <div>
20
+ <%= link_to 'Posts', admin_posts_path %>
21
+ <%= link_to 'Tags', admin_tags_path %>
22
+ <a>Settings</a>
23
+ </div>
24
+
25
+ <a class='profile'>
26
+ <%= current_user.display_name %>
27
+ </a>
28
+ </nav>
29
+ <%= main_tag class: [content_for('Content::Class')], 'data-style' => content_for('Content::Style') || 'plain' do %>
12
30
  <%= yield %>
13
31
  <% end %>
14
32
  <% end %>
@@ -5,6 +5,7 @@ require 'kaminari'
5
5
  require 'observejs'
6
6
  require 'written'
7
7
  require 'pg_search'
8
+ require 'autoprefixer-rails'
8
9
 
9
10
  module Ecrire
10
11
  ##
@@ -23,15 +24,7 @@ module Ecrire
23
24
  #
24
25
  #
25
26
  class Application < Rails::Application
26
- require 'ecrire/config/environment'
27
-
28
- config.before_initialize do
29
- if paths['config/database'].existent.any?
30
- require 'ecrire/theme/engine'
31
- else
32
- require 'ecrire/onboarding/engine'
33
- end
34
- end
27
+ attr_writer :pwd
35
28
 
36
29
  ##
37
30
  # There seems to be a crack between when the configuration
@@ -58,35 +51,66 @@ module Ecrire
58
51
  end
59
52
 
60
53
  ##
61
- # Return paths based off Rails default plus some customization.
54
+ # Override Rails secrets management as
55
+ # it doesn't allow us to do what we want.
56
+ # Then, Ecrire will merge anything that is
57
+ # through environment variables
62
58
  #
63
- # These paths are Ecrire's, not the users's theme.
64
- #
65
- # For the user's paths, look at Ecrire::Theme::Engine.paths
66
- #
67
- def paths
68
- @paths ||= begin
69
- paths = super
70
- paths.add 'config/secrets', with: Dir.pwd + '/secrets.yml'
71
- paths.add 'config/database', with: Dir.pwd + '/secrets.yml'
72
- paths.add 'config/routes.rb', with: 'routes.rb'
73
- paths.add 'config/locales', with: 'locales', glob: "**/*.{rb,yml}"
74
- paths
75
- end
59
+ def secrets
60
+ @secrets ||= begin
61
+ secrets = ActiveSupport::OrderedOptions.new
62
+ yaml = config.paths["config/secrets"].first
63
+
64
+ if File.exist?(yaml)
65
+ require "erb"
66
+ content = YAML.load(ERB.new(IO.read(yaml)).result) || {}
67
+ secrets.merge!(content.deep_symbolize_keys)
68
+ end
69
+
70
+ if ENV.has_key?(Ecrire::SECRET_ENVIRONMENT_KEY)
71
+ require 'json'
72
+ secrets.merge!(JSON.parse(ENV[Ecrire::SECRET_ENVIRONMENT_KEY]).deep_symbolize_keys)
73
+ end
74
+
75
+ # Fallback to config.secret_key_base if secrets.secret_key_base isn't set
76
+ secrets.secret_key_base ||= config.secret_key_base
77
+ # Fallback to config.secret_token if secrets.secret_token isn't set
78
+ secrets.secret_token ||= config.secret_token
79
+
80
+ secrets
81
+ end
76
82
  end
77
83
 
78
- ##
79
- # Returns true if Ecrire::Onboarding::Engine is loaded
80
- # in the application runtime
81
- #
82
- def self.onboarding?
83
- defined?(Ecrire::Onboarding::Engine)
84
+ def config
85
+ @config ||= Ecrire::Configuration.new(Pathname.new(self.class.called_from))
86
+ end
87
+
88
+ class << self
89
+
90
+ ##
91
+ # Returns true if Ecrire::Onboarding::Engine is loaded
92
+ # in the application runtime
93
+ #
94
+ def onboarding?
95
+ secrets.fetch(:onboarding, true)
96
+ end
97
+
84
98
  end
85
99
 
86
100
  Rails::Application::Bootstrap.initializers.select do |initializer|
87
101
  initializer.name.eql? :bootstrap_hook
88
102
  end.first.instance_variable_set :@block, Proc.new {}
89
103
 
104
+ config.before_initialize do
105
+ require 'ecrire/config/environment'
106
+ if onboarding?
107
+ require 'ecrire/onboarding/engine'
108
+ else
109
+ require 'ecrire/theme/engine'
110
+ end
111
+ end
112
+
113
+
90
114
  end
91
115
 
92
116
  end