notee 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,6 @@ module Notee
11
11
  end
12
12
 
13
13
  def show
14
- p @category
15
14
  render json: { status: 'success', category: @category}
16
15
  end
17
16
 
@@ -0,0 +1,29 @@
1
+ require_dependency "notee/application_controller"
2
+
3
+ module Notee
4
+ class CommentsController < ApplicationController
5
+
6
+ def show
7
+ @comments = Comment.where(post_id: params[:id]);
8
+ render json: { status: 'success', comments: @comments}
9
+ end
10
+
11
+ # POST /comments
12
+ def create
13
+ @comment = Comment.new(comment_params)
14
+
15
+ if @comment.save
16
+ render json: { status: 'success'}
17
+ else
18
+ render json: { status: 'failed'}
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ # Only allow a trusted parameter "white list" through.
25
+ def comment_params
26
+ params.require(:comment).permit(:post_id, :content, :name, :email)
27
+ end
28
+ end
29
+ end
@@ -54,7 +54,7 @@ module Notee
54
54
 
55
55
  # Only allow a trusted parameter "white list" through.
56
56
  def post_params
57
- params.require(:post).permit(:title, :content, :slug, :status, :category_id, :thumbnail_id, :published_at, :seo_keyword, :seo_description)
57
+ params.require(:post).permit(:title, :content, :slug, :status, :category_id, :thumbnail_id, :published_at, :seo_keyword, :seo_description, :secret_published_password)
58
58
  end
59
59
  end
60
60
  end
@@ -0,0 +1,4 @@
1
+ module Notee
2
+ module CommentsHelper
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Notee
2
+ class Comment < ApplicationRecord
3
+ validates :post_id, presence: true
4
+ validates :content, presence: true
5
+ end
6
+ end
@@ -0,0 +1,130 @@
1
+ <div class="notee_comment_box">
2
+ <comments post_id='<%= post_id %>'></comments>
3
+ <comment_form post_id='<%= post_id %>'></comment_form>
4
+ </div>
5
+
6
+
7
+ <!-- <comment> tag -->
8
+
9
+ <script type="riot/tag">
10
+
11
+ var obs = riot.observable();
12
+
13
+ /////////////////////////////////////////
14
+ // comment_form tag
15
+ /////////////////////////////////////////
16
+
17
+ <comment_form class="notee_comment_form" id="notee_form">
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
+ <input
29
+ type="submit"
30
+ value="Create Comment"
31
+ class="notee_submit"
32
+ data-disable-with="Create Comment"
33
+ onClick={notee_submit} />
34
+
35
+ this.notee_submit = function(e){
36
+ e.preventDefault();
37
+ var comment = {
38
+ post_id: opts.post_id,
39
+ name: document.getElementById("comment_name").value,
40
+ email: document.getElementById("comment_email").value,
41
+ content: document.getElementById("comment_content").value
42
+ };
43
+
44
+ if(comment.content != null){
45
+ var request = window.superagent;
46
+ var url = "/notee/api/comments";
47
+ var self = this;
48
+
49
+ request
50
+ .post(url)
51
+ .send({ comment: comment })
52
+ .end(function(err, res){
53
+ if(res.status == 200){
54
+ obs.trigger("notee_submit");
55
+ document.getElementById("comment_name").value = "";
56
+ document.getElementById("comment_email").value = "";
57
+ document.getElementById("comment_content").value = "";
58
+ }
59
+ });
60
+ }
61
+ }
62
+
63
+ </comment_form>
64
+
65
+
66
+
67
+ /////////////////////////////////////////
68
+ // comment tag
69
+ /////////////////////////////////////////
70
+
71
+
72
+ <comment class="notee_comment">
73
+ <p class="notee_comment_name">{ name }</p>
74
+ <p class="notee_comment_content"> { content } </p>
75
+
76
+ this.name = opts.name;
77
+ this.content = opts.content;
78
+ </comment>
79
+
80
+
81
+
82
+ /////////////////////////////////////////
83
+ // comments tag
84
+ /////////////////////////////////////////
85
+
86
+
87
+ <comments class="notee_comments">
88
+ <comment
89
+ each={ item in items }
90
+ name={item.name}
91
+ content={item.content}>
92
+ </comment>
93
+
94
+ var request = window.superagent;
95
+ var url = "/notee/api/comments/" + opts.post_id
96
+ var self = this;
97
+
98
+ this.one('update', function() {
99
+ request
100
+ .get(url)
101
+ .end(function(err, res){
102
+ console.log(res.body.comments);
103
+ self.items = res.body.comments;
104
+ self.update();
105
+ });
106
+ })
107
+
108
+ obs.on("notee_submit", function() {
109
+ request
110
+ .get(url)
111
+ .end(function(err, res){
112
+ console.log(res.body.comments);
113
+ self.items = res.body.comments;
114
+ self.update();
115
+ });
116
+ });
117
+
118
+ </comments>
119
+ </script>
120
+
121
+
122
+ <!-- Riot.js Settings -->
123
+
124
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/riot/2.3.18/riot+compiler.js"></script>
125
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/2.1.0/superagent.min.js"></script>
126
+ <script>
127
+ window.onload = function() {
128
+ riot.mount('*');
129
+ };
130
+ </script>
@@ -0,0 +1,15 @@
1
+ <% unless display %>
2
+ <div style="width: 100%; float: left">
3
+ <div style="width: 40%; margin-left: 26%; margin-top: 60px; border: 1px solid #dcdcdc; padding: 4%;">
4
+ <h1>Secret Notee</h1>
5
+ <p>Enter this notee's password</p>
6
+ <form style="margin-top: 40px;">
7
+ <h3>PASSWORD:</h3>
8
+ <input type="password" id="password" />
9
+ <button type="button" onClick="validate()">ENTER</button>
10
+ </form>
11
+ </div>
12
+ </div>
13
+ <% else %>
14
+ <%= markdown %>
15
+ <% end %>
data/config/routes.rb CHANGED
@@ -7,6 +7,7 @@ Notee::Engine.routes.draw do
7
7
  get 'category' => 'notees#index'
8
8
  get 'image' => 'notees#index'
9
9
 
10
+ post 'secret_published' => 'notees#secret_published'
10
11
  resources :tokens, only: [:new, :create, :destroy]
11
12
 
12
13
  scope :api, { format: 'json' } do
@@ -14,5 +15,6 @@ Notee::Engine.routes.draw do
14
15
  resources :images, only: [:index, :show, :create, :destroy]
15
16
  resources :categories, only: [:index, :show, :create, :update, :destroy]
16
17
  resources :statuses, only: [:index, :show]
18
+ resources :comments, only: [:show, :create]
17
19
  end
18
20
  end
@@ -5,7 +5,7 @@ class CreateNoteePosts < ActiveRecord::Migration
5
5
 
6
6
  # notee's base
7
7
 
8
- t.string :title, default: "no title"
8
+ t.string :title
9
9
  t.text :content
10
10
  t.string :slug
11
11
  t.integer :status, default: 0
@@ -17,6 +17,8 @@ class CreateNoteePosts < ActiveRecord::Migration
17
17
  t.string :seo_keyword, default: ""
18
18
  t.string :seo_description, default: ""
19
19
 
20
+ # secret_published
21
+ t.string :secret_published_password
20
22
 
21
23
  # if you have user_id
22
24
  # t.integer :user_id
@@ -15,6 +15,6 @@ class CreateNoteeCategories < ActiveRecord::Migration
15
15
  add_index :notee_categories, [:slug], :unique => true
16
16
 
17
17
  # create default category
18
- Notee::Category.create :name => 'None'
18
+ Notee::Category.create :name => 'No_Category'
19
19
  end
20
20
  end
@@ -0,0 +1,13 @@
1
+ class CreateNoteeComments < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :notee_comments do |t|
4
+ t.integer :post_id
5
+ t.text :content
6
+ t.string :name
7
+ t.string :email
8
+ t.boolean :is_hidden
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
data/lib/notee/engine.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'notee/helper'
2
- require 'notee/view_helper'
1
+ require 'notee/helpers/notee_helper'
2
+ require 'notee/helpers/view_helper'
3
3
 
4
4
  module Notee
5
5
  class Engine < ::Rails::Engine
@@ -11,14 +11,14 @@ module Notee
11
11
 
12
12
  initializer 'notee.action_controller_helpers' do
13
13
  ActiveSupport.on_load :action_controller do
14
- include Notee::Helper
14
+ include Notee::Helpers::NoteeHelper
15
15
  end
16
16
  end
17
17
 
18
18
  initializer 'notee.action_view_helpers' do
19
19
  ActiveSupport.on_load :action_view do
20
- include Notee::Helper
21
- include Notee::ViewHelper
20
+ include Notee::Helpers::NoteeHelper
21
+ include Notee::Helpers::ViewHelper
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1,72 @@
1
+ module Notee
2
+ module Helpers
3
+ module NoteeHelper
4
+
5
+ def notee(search_txt)
6
+ return false unless search_txt
7
+ @notee = Notee::Post.find_by(id: search_txt)
8
+ @notee = Notee::Post.find_by(slug: search_txt) unless @notee
9
+
10
+ return if @notee.status == Notee::STATUS[:draft] ||
11
+ @notee.status == Notee::STATUS[:deleted] ||
12
+ @notee.status == Notee::STATUS[:privated]
13
+ @notee
14
+ end
15
+
16
+ def notees(search_txt = 'all')
17
+ @notees = []
18
+
19
+ if search_txt == 'all'
20
+ # all_notees
21
+ @notees = Notee::Post.where(status: Notee::STATUS[:published]).order(published_at: :desc)
22
+ else
23
+ # search_by_category_slug
24
+ category_id = Notee::Category.find_by(slug: search_txt)
25
+ category_id = Notee::Category.find_by(name: search_txt) unless category_id
26
+ return false unless category_id
27
+
28
+ @notees = Notee::Post.where(category_id: category_id, status: Notee::STATUS[:published]).order(published_at: :desc)
29
+ end
30
+
31
+ @notees
32
+ end
33
+
34
+ # TODO: secret_mode
35
+ # def secret_notees
36
+ # @notees = Notee::Post.where(status: Notee::STATUS[:secret_published]).order(published_at: :desc)
37
+ # end
38
+
39
+ def notee_categories(sort = nil)
40
+ @notee_categories = Notee::Category.all.order(created_at: :desc)
41
+
42
+ case sort
43
+ when 'alphabetal'
44
+ @notee_categories = @notee_categories.sort
45
+ when 'size'
46
+ @notee_categories = @notee_categories.sort_by {|category| category.name.size }
47
+ end
48
+
49
+ @notee_categories
50
+ end
51
+
52
+ def notee_archives(year, month)
53
+ start_date = Date.new(year, month, 1)
54
+ end_date = Date.new(year, month, -1)
55
+ @notee_archives = Notee::Post.where(status: Notee::STATUS[:published], :published_at => start_date...end_date)
56
+
57
+ @notee_archives
58
+ end
59
+
60
+ def notee_archives_menu(type = nil)
61
+ case type
62
+ when 'year'
63
+ return Notee::Post.where(status: Notee::STATUS[:published]).group('year(published_at)').count
64
+ when 'month'
65
+ return Notee::Post.where(status: Notee::STATUS[:published]).group('year(published_at)').group('month(published_at)').count
66
+ else
67
+ return Notee::Post.where(status: Notee::STATUS[:published]).group('year(published_at)').group('month(published_at)').count
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,30 @@
1
+ require 'redcarpet'
2
+
3
+ module Notee
4
+ module Helpers
5
+ module ViewHelper
6
+ def notee_content (notee)
7
+
8
+ return if notee.nil?
9
+
10
+ unless @markdown
11
+ renderer = Redcarpet::Render::HTML.new(filter_html: true, hard_wrap: true)
12
+ @markdown = Redcarpet::Markdown.new(renderer, :fenced_code_blocks => true, :highlight => true)
13
+ end
14
+
15
+ # TODO: secret_mode
16
+ # if notee.status == Notee::STATUS[:secret_published]
17
+ # return render :partial => "notee/partials/secret_published.html.erb", :locals => { :item => notee, :markdown => @markdown.render(notee.content).html_safe, :display => false }
18
+ # end
19
+
20
+ @markdown.render(notee.content).html_safe
21
+ end
22
+
23
+ def notee_comment_box(id)
24
+ @comments = Notee::Comment.where(post_id: id)
25
+ @comment = Notee::Comment.new
26
+ return render :partial => "notee/partials/comment_box.html.erb", :locals => { :post_id => id}
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/notee/status.rb CHANGED
@@ -4,7 +4,8 @@ module Notee
4
4
  STATUS = {
5
5
  :draft => 0,
6
6
  :published => 1,
7
- :secret_published => 2,
7
+ # TODO: secret_mode
8
+ # :secret_published => 2,
8
9
  :privated => 3,
9
10
  :deleted => 4
10
11
  }
data/lib/notee/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Notee
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -0,0 +1,59 @@
1
+
2
+ /* notee_comment_box */
3
+
4
+ .notee_comment_box {
5
+ width: 100%;
6
+ margin: 30px auto;
7
+ float: left;
8
+ }
9
+
10
+ .notee_comments {
11
+ width: 94%;
12
+ padding: 3%;
13
+ margin_bottom: 20px;
14
+ float: left;
15
+ }
16
+
17
+ .notee_comment {
18
+ width: 98%;
19
+ padding: 1%;
20
+ margin_bottom: 10px;
21
+ border-bottom: 1px solid #dcdcdc;
22
+ float: left;
23
+ }
24
+ .notee_comment_form {
25
+ width: 60%;
26
+ padding: 4%;
27
+ margin_bottom: 20px;
28
+ float: left;
29
+ }
30
+
31
+ .notee_label {
32
+ width: 60%;
33
+ margin-bottom: 15px;
34
+ float: left;
35
+ }
36
+
37
+ .notee_text_field {
38
+ width: 60%;
39
+ height: 26px;
40
+ min-width: 300px;
41
+ margin-bottom: 15px;
42
+ float: left;
43
+ font-size: 14px;
44
+ }
45
+
46
+ .notee_text_area {
47
+ width: 100%;
48
+ height: 78px;
49
+ margin-bottom: 15px;
50
+ float: left;
51
+ font-size: 14px;
52
+ }
53
+
54
+ .notee_submit {
55
+ width: 100%;
56
+ margin-bottom: 15px;
57
+ float: left;
58
+ font-size: 30px;
59
+ }