notee 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/notee/application.js +45 -76973
  3. data/app/controllers/notee/comments_controller.rb +1 -1
  4. data/app/controllers/notee/tokens_controller.rb +15 -0
  5. data/app/models/notee/post.rb +1 -1
  6. data/app/models/notee/user.rb +0 -6
  7. data/app/views/notee/partials/_comment_box.html.erb +109 -120
  8. data/app/views/notee/partials/_meta.html.erb +3 -1
  9. data/app/views/notee/tokens/new.html.erb +16 -4
  10. data/config/routes.rb +2 -16
  11. data/db/migrate/20160605141437_create_notee_posts.rb +56 -1
  12. data/db/migrate/20160809145754_create_notee_users.rb +5 -0
  13. data/lib/notee/helpers/notee_helper.rb +8 -4
  14. data/lib/notee/version.rb +1 -1
  15. data/lib/tasks/config/notee.rb +1 -1
  16. data/lib/tasks/controllers/errors_controller.rb +23 -0
  17. data/lib/tasks/controllers/notee_controller.rb +1 -0
  18. data/lib/tasks/notee_tasks.rake +86 -48
  19. data/lib/tasks/stylesheets/notee/social/social.css +1 -0
  20. data/lib/tasks/views/layouts/notee_application.html.erb +6 -0
  21. data/lib/tasks/views/notee/about.html.erb +36 -41
  22. data/lib/tasks/views/notee/archives.html.erb +9 -14
  23. data/lib/tasks/views/notee/categories.html.erb +9 -14
  24. data/lib/tasks/views/notee/errors/internal_server_error.html.erb +5 -0
  25. data/lib/tasks/views/notee/errors/not_found.html.erb +5 -0
  26. data/lib/tasks/views/notee/partials/_footer.html.erb +5 -3
  27. data/lib/tasks/views/notee/partials/_header.html.erb +11 -1
  28. data/lib/tasks/views/notee/posts.html.erb +41 -44
  29. data/lib/tasks/views/notee/show.html.erb +29 -34
  30. data/lib/tasks/views/notee/writers.html.erb +5 -10
  31. data/test/controllers/notee/categories_controller_test.rb +2 -2
  32. data/test/controllers/notee/comments_controller_test.rb +2 -2
  33. data/test/controllers/notee/images_controller_test.rb +2 -2
  34. data/test/controllers/notee/posts_controller_test.rb +2 -2
  35. metadata +6 -2
@@ -1,7 +1,7 @@
1
1
  require_dependency 'notee/application_controller'
2
2
 
3
3
  module Notee
4
- class CommentsController < ApplicationController
4
+ class CommentsController < ActionController::Base
5
5
  before_action :set_comment, only: [:update, :destroy]
6
6
 
7
7
  def index
@@ -1,6 +1,10 @@
1
1
 
2
2
  require_dependency 'notee/application_controller'
3
3
 
4
+ require 'open-uri'
5
+ require 'json'
6
+ require 'uri'
7
+
4
8
  module Notee
5
9
  class TokensController < ApplicationController
6
10
  skip_before_filter :restrict_access_json, only: [:new, :create]
@@ -9,6 +13,7 @@ module Notee
9
13
  end
10
14
 
11
15
  def create
16
+ check_recaptcha
12
17
  User.sign_in(params[:id], params[:password])
13
18
  redirect_to root_path
14
19
  end
@@ -23,5 +28,15 @@ module Notee
23
28
  end
24
29
  end
25
30
  end
31
+
32
+ def check_recaptcha
33
+ endpoint = 'https://www.google.com/recaptcha/api/siteverify?secret=' + Notee.recaptcha_secret_key + '&response=' + params["g-recaptcha-response"]
34
+ uri = URI.parse(endpoint)
35
+ json = Net::HTTP.get(uri)
36
+ result = JSON.parse(json)
37
+ if result["success"] == false
38
+ raise
39
+ end
40
+ end
26
41
  end
27
42
  end
@@ -43,7 +43,7 @@ module Notee
43
43
  end
44
44
 
45
45
  def set_slug
46
- self.slug = self.title.downcase unless self.slug.present?
46
+ self.slug = self.title.parameterize.underscore unless self.slug.present?
47
47
  end
48
48
 
49
49
  def set_published_at
@@ -67,12 +67,6 @@ module Notee
67
67
  end
68
68
 
69
69
  def self.root_user_setting
70
- unless User.exists?(id: 0)
71
- User.skip_callback(:create, :before, :create_authority)
72
- User.create(id: 0, name: Notee.notee_id, email: "root", password: SecureRandom.hex, role: 9999)
73
- User.set_callback(:create, :before, :create_authority)
74
- end
75
-
76
70
  if token = Token.create!(user_id: 0)
77
71
  Thread.current[:request].session[:access_token] = token.access_token
78
72
  end
@@ -1,137 +1,126 @@
1
+
2
+ <!-- Riot.js Settings -->
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/riot/2.3.18/riot+compiler.js"></script>
4
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/2.1.0/superagent.min.js"></script>
5
+ <script src="https://www.google.com/recaptcha/api.js" async defer></script>
6
+
7
+
1
8
  <div class="notee_list">
2
9
  <comments post_id='<%= post_id %>'></comments>
10
+ <div data-callback="syncerRecaptchaCallback" class="g-recaptcha notee_comment_form" data-sitekey="<%= recaptcha %>"></div>
3
11
  <comment_form post_id='<%= post_id %>'></comment_form>
4
12
  </div>
5
13
 
6
- <!-- <comment> tag -->
7
14
 
8
15
  <script type="riot/tag">
9
-
10
- var obs = riot.observable();
11
-
12
- /////////////////////////////////////////
13
- // comment_form tag
14
- /////////////////////////////////////////
15
-
16
- <comment_form class="notee_comment_form" id="notee_form">
17
- <form method="POST">
18
-
19
- <label class="notee_label" for="comment_name">Name</label>
20
- <input class="notee_text_field" type="text" name="comment[name]" id="comment_name" />
21
-
22
- <label class="notee_label" for="comment_email">Email</label>
23
- <input class="notee_text_field" type="text" name="comment[email]" id="comment_email" />
24
-
25
- <label class="notee_label" for="comment_content">Content</label>
26
- <textarea class="notee_text_area" name="comment[content]" id="comment_content"></textarea>
27
-
28
- <div class="g-recaptcha" data-sitekey="<%= recaptcha %>"></div>
29
-
30
- <input
31
- type="submit"
32
- value="Create Comment"
33
- class="notee_submit"
34
- data-disable-with="Create Comment"
35
- onClick={notee_submit} />
36
-
37
- </form>
38
-
39
- this.notee_submit = function(e){
40
- e.preventDefault();
41
- var comment = {
42
- post_id: opts.post_id,
43
- name: document.getElementById("comment_name").value,
44
- email: document.getElementById("comment_email").value,
45
- content: document.getElementById("comment_content").value
46
- };
47
-
48
- if(comment.content != null || comment.content != ""){
49
- var request = window.superagent;
50
- var url = "/notee/api/comments";
51
- var self = this;
52
-
53
- request
54
- .post(url)
55
- .send({ comment: comment })
56
- .end(function(err, res){
57
- if(res.status == 200){
58
- obs.trigger("notee_submit");
59
- document.getElementById("comment_name").value = "";
60
- document.getElementById("comment_email").value = "";
61
- document.getElementById("comment_content").value = "";
62
- }
63
- });
64
- }
65
- }
66
-
67
- </comment_form>
68
-
69
-
70
-
71
- /////////////////////////////////////////
72
- // comment tag
73
- /////////////////////////////////////////
74
-
75
16
 
76
- <comment class="notee_comment">
77
- <p class="notee_comment_name">{ name }</p>
78
- <p class="notee_comment_content"> { content } </p>
17
+ var obs = riot.observable();
79
18
 
80
- this.name = opts.name;
81
- this.content = opts.content;
82
- </comment>
19
+ <comment_form class="notee_comment_form" id="notee_form">
20
+ <form method="POST" id="syncer-recaptcha-form">
21
+ <label class="notee_label" for="comment_name">Name</label>
22
+ <input class="notee_text_field" type="text" name="comment[name]" id="comment_name" disabled />
83
23
 
24
+ <label class="notee_label" for="comment_email">Email</label>
25
+ <input class="notee_text_field" type="text" name="comment[email]" id="comment_email" disabled />
84
26
 
27
+ <label class="notee_label" for="comment_content">Content</label>
28
+ <textarea class="notee_text_area" name="comment[content]" id="comment_content" disabled></textarea>
85
29
 
86
- /////////////////////////////////////////
87
- // comments tag
88
- /////////////////////////////////////////
89
-
90
-
91
- <comments class="notee_comments">
92
- <comment
93
- each={ item in items }
94
- name={item.name}
95
- content={item.content}>
96
- </comment>
97
-
98
- var request = window.superagent;
99
- var url = "/notee/api/comments/" + opts.post_id
100
- var self = this;
101
-
102
- this.one('update', function() {
103
- request
104
- .get(url)
105
- .end(function(err, res){
106
- console.log(res.body.comments);
107
- self.items = res.body.comments;
108
- self.update();
109
- });
110
- })
111
-
112
- obs.on("notee_submit", function() {
113
- request
114
- .get(url)
115
- .end(function(err, res){
116
- console.log(res.body.comments);
117
- self.items = res.body.comments;
118
- self.update();
119
- });
120
- });
30
+ <input
31
+ type="submit"
32
+ value="Create Comment"
33
+ class="notee_submit"
34
+ data-disable-with="Create Comment"
35
+ onClick={notee_submit}
36
+ disabled />
37
+ </form>
121
38
 
122
- </comments>
39
+ this.notee_submit = function(e){
40
+ e.preventDefault();
41
+ var comment = {
42
+ post_id: opts.post_id,
43
+ name: document.getElementById("comment_name").value,
44
+ email: document.getElementById("comment_email").value,
45
+ content: document.getElementById("comment_content").value
46
+ };
47
+
48
+ if(comment.content != null || comment.content != ""){
49
+ var request = window.superagent;
50
+ var url = "/notee/api/comments";
51
+ var self = this;
52
+
53
+ request
54
+ .post(url)
55
+ .send({ comment: comment })
56
+ .end(function(err, res){
57
+ if(res.status == 200){
58
+ obs.trigger("notee_submit");
59
+ document.getElementById("comment_name").value = "";
60
+ document.getElementById("comment_email").value = "";
61
+ document.getElementById("comment_content").value = "";
62
+ }
63
+ });
64
+ }
65
+ }
66
+ </comment_form>
67
+
68
+ <comment class="notee_comment">
69
+ <p class="notee_comment_name">{ name }</p>
70
+ <p class="notee_comment_content"> { content } </p>
71
+
72
+ this.name = opts.name;
73
+ this.content = opts.content;
74
+ </comment>
75
+
76
+ <comments class="notee_comments">
77
+ <comment
78
+ each={ item in items }
79
+ name={item.name}
80
+ content={item.content}>
81
+ </comment>
82
+
83
+ var request = window.superagent;
84
+ var url = "/notee/api/comments/" + opts.post_id;
85
+ var self = this;
86
+
87
+ this.one('update', function() {
88
+ request
89
+ .get(url)
90
+ .end(function(err, res){
91
+ if(res.body != null){
92
+ self.items = res.body.comments;
93
+ self.update();
94
+ }
95
+ });
96
+ })
97
+
98
+ obs.on("notee_submit", function() {
99
+ request
100
+ .get(url)
101
+ .end(function(err, res){
102
+ self.items = res.body.comments;
103
+ self.update();
104
+ });
105
+ });
106
+ </comments>
123
107
  </script>
124
108
 
125
-
126
-
127
-
128
- <!-- Riot.js Settings -->
129
-
130
- <script src="https://cdnjs.cloudflare.com/ajax/libs/riot/2.3.18/riot+compiler.js"></script>
131
- <script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/2.1.0/superagent.min.js"></script>
132
- <script src="https://www.google.com/recaptcha/api.js" async defer></script>
133
109
  <script>
134
- window.onload = function() {
135
- riot.mount('*');
136
- };
110
+ if(window.addEventListener) {
111
+ window.addEventListener( "load" , riot_mount, false );
112
+ }else{
113
+ window.attachEvent( "onload", riot_mount );
114
+ }
115
+
116
+ function riot_mount(){
117
+ riot.mount('*');
118
+ }
119
+
120
+ function syncerRecaptchaCallback( code ){
121
+ if(code != ""){
122
+ $( '#syncer-recaptcha-form input , #syncer-recaptcha-form button, #syncer-recaptcha-form textarea' ).removeAttr( 'disabled' ) ;
123
+ }
124
+ }
125
+
137
126
  </script>
@@ -1,6 +1,8 @@
1
1
 
2
2
  <!-- Notee Meta Info -->
3
3
 
4
+ <% meta ||= Notee.blog_meta %>
5
+
4
6
  <title><%= meta[:title] %></title>
5
7
  <meta name="keywords" content="<%= meta[:keyword] %>"/>
6
8
  <meta name="description" content="<%= meta[:description] %>"/>
@@ -22,4 +24,4 @@
22
24
  ga('create', '<%= ga %>', 'auto');
23
25
  ga('send', 'pageview');
24
26
 
25
- </script>
27
+ </script>
@@ -1,13 +1,25 @@
1
+ <script src="https://www.google.com/recaptcha/api.js" async defer></script>
2
+
1
3
  <div class="grid_start login_bg">
2
4
  <div class="fourty grid offset_by_twenty_five mt_60 login">
3
5
  <h1>Notee</h1>
4
6
  <p>Notee is creating blog gem by only one command</p>
5
- <%= form_tag(tokens_path, :class => 'mt_50') do %>
7
+ <%= form_tag(tokens_path, :class => 'mt_50', :id => 'syncer-recaptcha-form') do %>
6
8
  <h3>ID:</h3>
7
- <%= text_field_tag :id %>
9
+ <%= text_field_tag :id, "", :disabled => true %>
8
10
  <h3>PASSWORD:</h3>
9
- <%= password_field_tag :password %>
10
- <%= submit_tag "ログイン", :class => 'full grid mt_50' %>
11
+ <%= password_field_tag :password, "", :disabled => true %>
12
+ <div data-callback="syncerRecaptchaCallback" class="g-recaptcha mt_30" data-sitekey="<%= Notee.recaptcha_key %>"></div>
13
+ <%= submit_tag "ログイン", :disabled => true, :class => 'full grid mt_50' %>
11
14
  <% end %>
12
15
  </div>
13
16
  </div>
17
+
18
+ <script>
19
+ function syncerRecaptchaCallback( code ){
20
+ if(code != ""){
21
+ $( '#syncer-recaptcha-form input , #syncer-recaptcha-form button, #syncer-recaptcha-form textarea' ).removeAttr( 'disabled' ) ;
22
+ }
23
+ }
24
+ </script>
25
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
data/config/routes.rb CHANGED
@@ -2,22 +2,6 @@ Notee::Engine.routes.draw do
2
2
 
3
3
  root to: 'notees#index'
4
4
 
5
- get 'posts' => 'notees#index'
6
- get 'posts/new' => 'notees#index'
7
- get 'posts/edit/:id' => 'notees#index'
8
- get 'categories' => 'notees#index'
9
- get 'categories/edit/:id' => 'notees#index'
10
- get 'images' => 'notees#index'
11
- get 'comments' => 'notees#index'
12
- get 'users' => 'notees#index'
13
- get 'users/new' => 'notees#index'
14
- get 'users/edit/:id' => 'notees#index'
15
- get 'trashes' => 'notees#index'
16
- get 'trashes/:model' => 'notees#index'
17
- get 'mypage' => 'notees#index'
18
- get 'mypage/edit' => 'notees#index'
19
- get 'mypage/edit/password' => 'notees#index'
20
-
21
5
  # post 'secret_published' => 'notees#secret_published'
22
6
  resources :tokens, only: [:new, :create, :destroy]
23
7
 
@@ -33,4 +17,6 @@ Notee::Engine.routes.draw do
33
17
  resources :roles, only: [:index, :show]
34
18
  resources :trashes, only: [:index, :update]
35
19
  end
20
+
21
+ get '*anything' => 'notees#index'
36
22
  end
@@ -1,4 +1,55 @@
1
1
  # This migration comes from notee (originally 20160605141437)
2
+
3
+ INITIAL_TXT = <<-EOC
4
+
5
+ # Notee
6
+
7
+ Notee is creating CMS(blog) app by only one command.
8
+
9
+ BackEnd: Ruby(RailsEngine)
10
+ FrontEnd: React.js + Riot.js(only comment part)
11
+
12
+ ## Setting
13
+
14
+ update for your setting in config/initializers/notee.rb
15
+
16
+ Recommendation using .env
17
+
18
+ ```rb
19
+ require 'notee'
20
+
21
+ # Recommendation using .env for manage id & password
22
+
23
+ Notee.configure do |config|
24
+
25
+ # root-user
26
+ config.notee_id = "your_name"
27
+ config.notee_password = "your_password"
28
+
29
+ # recaptcha
30
+ config.recaptcha_key = "hogehoge"
31
+ config.recaptcha_secret_key = "hogehoge"
32
+
33
+ # blog
34
+ config.blog_meta = {
35
+ title: "Notee",
36
+ url: "http://hogehoge.com",
37
+ keyword: "hoge, hoge, hoge",
38
+ description: "【react&rails】notee is creating CMS(blog) app by only one command.",
39
+ og_image: "http://hogehoge.com/hoge.png"
40
+ }
41
+
42
+ # google-analytics
43
+ config.google_analytics = "hogehogehogehoge"
44
+ end
45
+
46
+ ```
47
+
48
+ ## Helper Method
49
+ [Helper Method](https://github.com/funaota/notee/wiki/Helper-Method)
50
+
51
+ EOC
52
+
2
53
  class CreateNoteePosts < ActiveRecord::Migration
3
54
  def change
4
55
  create_table :notee_posts do |t|
@@ -23,9 +74,13 @@ class CreateNoteePosts < ActiveRecord::Migration
23
74
 
24
75
 
25
76
  t.timestamps null: false
26
-
27
77
  end
28
78
 
79
+ # create default post
80
+ Notee::Post.skip_callback(:create, :before, :create_authority)
81
+ Notee::Post.create(title: "Hello World", content: INITIAL_TXT, status: 1, user_id: 0, category_id: 1, seo_description: "hello world! Notee is creating CMS(blog) app by only one command. BackEnd: Ruby(RailsEngine), FrontEnd: React.js + Riot.js(only comment part)", thumbnail_id: 1)
82
+ Notee::Post.set_callback(:create, :before, :create_authority)
83
+
29
84
  add_index :notee_posts, :slug, :unique => true
30
85
  end
31
86
  end