notee 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +44 -4
  4. data/app/assets/javascripts/application.js +14 -0
  5. data/app/assets/javascripts/notee/application.js +47366 -0
  6. data/app/assets/stylesheets/notee/application.css +15 -0
  7. data/app/assets/stylesheets/notee/images.css +4 -0
  8. data/app/assets/stylesheets/notee/posts.css +4 -0
  9. data/app/assets/stylesheets/notee/preview.scss +214 -0
  10. data/app/assets/stylesheets/scaffold.css +56 -0
  11. data/app/controllers/notee/application_controller.rb +24 -0
  12. data/app/controllers/notee/categories_controller.rb +55 -0
  13. data/app/controllers/notee/images_controller.rb +48 -0
  14. data/app/controllers/notee/posts_controller.rb +75 -0
  15. data/app/controllers/notee/tokens_controller.rb +30 -0
  16. data/app/helpers/notee/application_helper.rb +4 -0
  17. data/app/helpers/notee/categories_helper.rb +4 -0
  18. data/app/helpers/notee/images_helper.rb +4 -0
  19. data/app/helpers/notee/posts_helper.rb +4 -0
  20. data/app/models/notee/category.rb +4 -0
  21. data/app/models/notee/image.rb +24 -0
  22. data/app/models/notee/post.rb +4 -0
  23. data/app/models/notee/token.rb +18 -0
  24. data/app/views/layouts/notee/application.html.erb +14 -0
  25. data/app/views/notee/posts/notee.html.erb +1 -0
  26. data/app/views/notee/tokens/new.html.erb +5 -0
  27. data/config/routes.rb +12 -0
  28. data/db/migrate/20160605141437_create_notee_posts.rb +29 -0
  29. data/db/migrate/20160605141510_create_notee_categories.rb +15 -0
  30. data/db/migrate/20160605141547_create_notee_images.rb +14 -0
  31. data/db/migrate/20160608102012_create_notee_tokens.rb +12 -0
  32. data/lib/notee.rb +4 -2
  33. data/lib/notee/configuration.rb +28 -0
  34. data/lib/notee/engine.rb +13 -0
  35. data/lib/notee/version.rb +1 -1
  36. data/lib/tasks/notee_tasks.rake +71 -0
  37. data/test/controllers/notee/categories_controller_test.rb +52 -0
  38. data/test/controllers/notee/images_controller_test.rb +52 -0
  39. data/test/controllers/notee/posts_controller_test.rb +52 -0
  40. data/test/dummy/README.rdoc +28 -0
  41. data/test/dummy/Rakefile +6 -0
  42. data/test/dummy/app/assets/javascripts/application.js +13 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  44. data/test/dummy/app/controllers/application_controller.rb +5 -0
  45. data/test/dummy/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/test/dummy/bin/bundle +3 -0
  48. data/test/dummy/bin/rails +4 -0
  49. data/test/dummy/bin/rake +4 -0
  50. data/test/dummy/bin/setup +29 -0
  51. data/test/dummy/config.ru +4 -0
  52. data/test/dummy/config/application.rb +26 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/database.yml +25 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +41 -0
  57. data/test/dummy/config/environments/production.rb +79 -0
  58. data/test/dummy/config/environments/test.rb +42 -0
  59. data/test/dummy/config/initializers/assets.rb +11 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  62. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/test/dummy/config/initializers/inflections.rb +16 -0
  64. data/test/dummy/config/initializers/mime_types.rb +4 -0
  65. data/test/dummy/config/initializers/session_store.rb +3 -0
  66. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  67. data/test/dummy/config/locales/en.yml +23 -0
  68. data/test/dummy/config/routes.rb +4 -0
  69. data/test/dummy/config/secrets.yml +23 -0
  70. data/test/dummy/db/development.sqlite3 +0 -0
  71. data/test/dummy/db/schema.rb +16 -0
  72. data/test/dummy/db/test.sqlite3 +0 -0
  73. data/test/dummy/log/development.log +3259 -0
  74. data/test/dummy/public/404.html +67 -0
  75. data/test/dummy/public/422.html +67 -0
  76. data/test/dummy/public/500.html +66 -0
  77. data/test/dummy/public/favicon.ico +0 -0
  78. data/test/fixtures/notee/categories.yml +13 -0
  79. data/test/fixtures/notee/images.yml +7 -0
  80. data/test/fixtures/notee/posts.yml +23 -0
  81. data/test/fixtures/notee/tokens.yml +9 -0
  82. data/test/integration/navigation_test.rb +10 -0
  83. data/test/models/notee/category_test.rb +9 -0
  84. data/test/models/notee/image_test.rb +9 -0
  85. data/test/models/notee/post_test.rb +9 -0
  86. data/test/models/notee/token_test.rb +9 -0
  87. data/test/notee_test.rb +7 -0
  88. data/test/test_helper.rb +20 -0
  89. metadata +195 -33
  90. data/.gitignore +0 -10
  91. data/.idea/.name +0 -1
  92. data/.idea/misc.xml +0 -14
  93. data/.idea/modules.xml +0 -8
  94. data/.idea/notee.iml +0 -17
  95. data/.idea/vcs.xml +0 -6
  96. data/.idea/workspace.xml +0 -335
  97. data/.rspec +0 -2
  98. data/.travis.yml +0 -4
  99. data/CODE_OF_CONDUCT.md +0 -13
  100. data/Gemfile +0 -4
  101. data/LICENSE.txt +0 -21
  102. data/README.md +0 -41
  103. data/bin/console +0 -14
  104. data/bin/setup +0 -7
  105. data/lib/generators/notee/install/install_generator.rb +0 -17
  106. data/notee.gemspec +0 -28
@@ -0,0 +1,30 @@
1
+
2
+ require_dependency "notee/application_controller"
3
+
4
+ module Notee
5
+ class TokensController < ApplicationController
6
+ skip_before_filter :restrict_access_json, only: [:new, :create]
7
+
8
+ # GET /tokens/new
9
+ def new
10
+ end
11
+
12
+ # POST /tokens
13
+ def create
14
+ if Notee.notee_id == params[:id] && Notee.notee_password == params[:password]
15
+ if token = Token.create!
16
+ session[:access_token] = token.access_token
17
+ end
18
+ end
19
+
20
+ redirect_to root_path
21
+ end
22
+
23
+ # DELETE /tokens/1
24
+ def destroy
25
+ Token.find_by_access_token(session[:access_token]).destroy!
26
+ session.delete(:access_token)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module Notee
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Notee
2
+ module CategoriesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Notee
2
+ module ImagesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Notee
2
+ module PostsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Notee
2
+ class Category < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,24 @@
1
+ require 'securerandom'
2
+
3
+ module Notee
4
+ class Image < ActiveRecord::Base
5
+ attr_accessor :file
6
+ before_save :manage_image
7
+
8
+ def manage_image
9
+ return unless self.file
10
+
11
+ image_dir = Rails.root.to_s + "/public/notee"
12
+ FileUtils.mkdir_p(image_dir) unless FileTest.exist?(image_dir)
13
+
14
+ image_name = Time.now.strftime('%Y%m%d%H%M%S') + '--' + SecureRandom.uuid + '.jpg'
15
+ self.transaction do
16
+ open(image_dir + "/" + image_name, 'wb') do |output|
17
+ output.write(self.file.read)
18
+ end
19
+ self.content = image_name
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module Notee
2
+ class Post < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,18 @@
1
+ module Notee
2
+ class Token < ActiveRecord::Base
3
+ before_create :generate_access_token
4
+ before_create :set_expires_at
5
+
6
+ private
7
+
8
+ def generate_access_token
9
+ begin
10
+ self.access_token = SecureRandom.hex
11
+ end while self.class.exists?(access_token: access_token)
12
+ end
13
+
14
+ def set_expires_at
15
+ self.expires_at = Time.current + (60 * 60 * 24 * 7) #7日
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Notee</title>
5
+ <%= stylesheet_link_tag "notee/application", media: "all" %>
6
+ <%= javascript_include_tag "notee/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ <div id="react"></div>
@@ -0,0 +1,5 @@
1
+ <%= form_tag(tokens_path) do %>
2
+ <%= text_field_tag :id %>
3
+ <%= password_field_tag :password %>
4
+ <%= submit_tag "登録" %>
5
+ <% end %>
@@ -0,0 +1,12 @@
1
+ Notee::Engine.routes.draw do
2
+
3
+ root to: 'posts#notee'
4
+
5
+ resources :tokens, only: [:new, :create, :destroy]
6
+
7
+ namespace :api, { format: 'json', module: nil } do
8
+ resources :posts, only: [:index, :show, :create, :update, :destroy]
9
+ resources :images, only: [:index, :create, :destroy]
10
+ resources :categories, only: [:index, :show, :create, :update, :destroy]
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ class CreateNoteePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :notee_posts do |t|
4
+
5
+ # notee's base
6
+
7
+ t.string :title, null: false, default: "no title"
8
+ t.text :content, null: false, default: ""
9
+ t.string :slug, null: false, default: "#{Time.now.strftime("%Y-%H-%M-%S")}"
10
+ t.integer :status, null: false, default: 0
11
+ t.integer :category_id, default: 0
12
+ t.integer :thumbnail_id, default: 0
13
+ t.datetime :published_at, null: false, default: "#{Time.now.strftime("%Y-%H-%M-%S")}"
14
+
15
+ # seo
16
+ t.string :seo_keyword, null: false, default: ""
17
+ t.string :seo_description, null: false, default: ""
18
+
19
+
20
+ # if you have user_id
21
+ # t.integer :user_id
22
+
23
+ t.timestamps null: false
24
+
25
+ end
26
+
27
+ add_index :notee_posts, [:slug], :unique => true
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ class CreateNoteeCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :notee_categories do |t|
4
+
5
+ t.string :name, null: false, default: "category_name"
6
+ t.string :slug, null: false, default: "#{Time.now.strftime("%Y-%H-%M-%S")}", uniqueness: true
7
+ t.integer :parent_id
8
+ t.integer :status, null: false, default: 0
9
+
10
+ t.timestamps null: false
11
+ end
12
+
13
+ add_index :notee_categories, [:slug], :unique => true
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateNoteeImages < ActiveRecord::Migration
2
+ def change
3
+ create_table :notee_images do |t|
4
+
5
+ t.string :content, null: false, uniqueness: true
6
+
7
+ # if you have user_id
8
+ # t.integer :user_id
9
+
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,12 @@
1
+ class CreateNoteeTokens < ActiveRecord::Migration
2
+ def change
3
+ create_table :notee_tokens do |t|
4
+ t.string :access_token, null: false
5
+ t.datetime :expires_at, null: false
6
+
7
+ t.timestamps null: false
8
+ end
9
+
10
+ add_index :notee_tokens, [:access_token], :unique => true
11
+ end
12
+ end
@@ -1,5 +1,7 @@
1
- require "notee/version"
1
+ require 'notee/engine'
2
+ require 'notee/version'
3
+ require_relative 'notee/configuration'
2
4
 
3
5
  module Notee
4
- # Your code goes here...
6
+ extend Configuration
5
7
  end
@@ -0,0 +1,28 @@
1
+ module Notee
2
+ module Configuration
3
+
4
+ VALID_OPTIONS_KEY = [
5
+ :notee_id,
6
+ :notee_password
7
+ ].freeze
8
+
9
+ DEFAULT_NOTEE_ID = nil
10
+ DEFAULT_NOTEE_PASSWORD = nil
11
+
12
+ attr_accessor *VALID_OPTIONS_KEY
13
+
14
+ def configure
15
+ yield self
16
+ end
17
+
18
+ def self.extended(base)
19
+ base.reset
20
+ end
21
+
22
+ def reset
23
+ self.notee_id = DEFAULT_NOTEE_ID
24
+ self.notee_password = DEFAULT_NOTEE_PASSWORD
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ module Notee
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Notee
4
+
5
+ config.generators do |g|
6
+ g.template_engine :slim
7
+ end
8
+
9
+ initializer "notee.assets.precompile" do |app|
10
+ app.config.assets.precompile += %w(*.js *.css)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Notee
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,71 @@
1
+ desc 'setup notee'
2
+ namespace :notee do
3
+ task :start do
4
+ notee_mark
5
+ sh 'bundle exec rake notee:install:migrations'
6
+ add_engine_to_route
7
+ create_initializer_file
8
+ end
9
+
10
+ def notee_mark
11
+ puts "
12
+ ________________________________
13
+ ________________________________
14
+
15
+ |\\ |
16
+ | \\ | ___ __|__ __|__ __
17
+ | \\ | | | | | /__\\
18
+ | \\| |___| | | \\___
19
+
20
+ ________________________________
21
+ ________________________________
22
+
23
+ "
24
+ end
25
+
26
+ def add_engine_to_route
27
+ puts ""
28
+ return puts 'setup Notee Engine in config/route.rb\n' unless route_file = File.open("#{Rails.root}/config/routes.rb","r")
29
+
30
+ notee_routes_str = String.new
31
+ text = <<-EOC
32
+
33
+ mount Notee::Engine => "/notee"
34
+ EOC
35
+
36
+ route_file.each_line do |line|
37
+ line += text if line.include?("Rails.application.routes.draw do")
38
+ notee_routes_str += line
39
+ end
40
+
41
+ f = File.open("#{Rails.root}/config/routes.rb","w")
42
+ f.write(notee_routes_str)
43
+ f.close()
44
+
45
+ puts 'add "mount Notee::Engine => "/notee" to config/route.rb'
46
+ puts ""
47
+ end
48
+
49
+ def create_initializer_file
50
+ file_path = "#{Rails.root}/config/initializers/notee.rb"
51
+ return if File.exist?(file_path)
52
+
53
+ str = <<EOC
54
+ require 'notee'
55
+
56
+ # Recommendation using .env for manage id & password
57
+
58
+ Notee.configure do |config|
59
+ config.notee_id = "hogehoge"
60
+ config.notee_password = "hogehoge"
61
+ end
62
+ EOC
63
+
64
+ File.open(file_path,"w") do |file|
65
+ file.puts str
66
+ end
67
+ puts 'create file in "config/initializers/notee.rb"'
68
+ puts 'you should change notee_id & notee_password'
69
+ end
70
+
71
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ module Notee
4
+ class CategoriesControllerTest < ActionController::TestCase
5
+ setup do
6
+ @category = notee_categories(:one)
7
+ @routes = Engine.routes
8
+ end
9
+
10
+ test "should get index" do
11
+ get :index
12
+ assert_response :success
13
+ assert_not_nil assigns(:categories)
14
+ end
15
+
16
+ test "should get new" do
17
+ get :new
18
+ assert_response :success
19
+ end
20
+
21
+ test "should create category" do
22
+ assert_difference('Category.count') do
23
+ post :create, category: { name: @category.name, parent_id: @category.parent_id, slug: @category.slug, status: @category.status }
24
+ end
25
+
26
+ assert_redirected_to category_path(assigns(:category))
27
+ end
28
+
29
+ test "should show category" do
30
+ get :show, id: @category
31
+ assert_response :success
32
+ end
33
+
34
+ test "should get edit" do
35
+ get :notee, id: @category
36
+ assert_response :success
37
+ end
38
+
39
+ test "should update category" do
40
+ patch :update, id: @category, category: { name: @category.name, parent_id: @category.parent_id, slug: @category.slug, status: @category.status }
41
+ assert_redirected_to category_path(assigns(:category))
42
+ end
43
+
44
+ test "should destroy category" do
45
+ assert_difference('Category.count', -1) do
46
+ delete :destroy, id: @category
47
+ end
48
+
49
+ assert_redirected_to categories_path
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ module Notee
4
+ class ImagesControllerTest < ActionController::TestCase
5
+ setup do
6
+ @image = notee_images(:one)
7
+ @routes = Engine.routes
8
+ end
9
+
10
+ test "should get index" do
11
+ get :index
12
+ assert_response :success
13
+ assert_not_nil assigns(:images)
14
+ end
15
+
16
+ test "should get new" do
17
+ get :new
18
+ assert_response :success
19
+ end
20
+
21
+ test "should create image" do
22
+ assert_difference('Image.count') do
23
+ post :create, image: { content: @image.content }
24
+ end
25
+
26
+ assert_redirected_to image_path(assigns(:image))
27
+ end
28
+
29
+ test "should show image" do
30
+ get :show, id: @image
31
+ assert_response :success
32
+ end
33
+
34
+ test "should get edit" do
35
+ get :notee, id: @image
36
+ assert_response :success
37
+ end
38
+
39
+ test "should update image" do
40
+ patch :update, id: @image, image: { content: @image.content }
41
+ assert_redirected_to image_path(assigns(:image))
42
+ end
43
+
44
+ test "should destroy image" do
45
+ assert_difference('Image.count', -1) do
46
+ delete :destroy, id: @image
47
+ end
48
+
49
+ assert_redirected_to images_path
50
+ end
51
+ end
52
+ end