maeku_core 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90724e9c6d7fd1a4d118945dd92cf695686393668c9739dd5732d74184424f73
4
+ data.tar.gz: 03271eb8a95a7d29d1cdb960951bc5eb799c6ecbda2614be3c66419e8f583a75
5
+ SHA512:
6
+ metadata.gz: 0d1e9a2aa8b4965760d12987181e4dff30e9b3fea1ccf748db4380c1f223ec402ae8f4f2eb92ebc11cee946afc5506145298e367cfed34dd4cfa887266931b05
7
+ data.tar.gz: 141715cea766e7f1b1e36cb1ff4b95e49ec4840953ebc0a4def5edced98a20a7028b8167a92f000f023ac6947feb12835001e92bbd7317a21e002b6581398095
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Maeku'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/maeku .js
2
+ //= link_directory ../stylesheets/maeku .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,80 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ margin: 33px;
5
+ }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 13px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px;
17
+ }
18
+
19
+ a {
20
+ color: #000;
21
+ }
22
+
23
+ a:visited {
24
+ color: #666;
25
+ }
26
+
27
+ a:hover {
28
+ color: #fff;
29
+ background-color: #000;
30
+ }
31
+
32
+ th {
33
+ padding-bottom: 5px;
34
+ }
35
+
36
+ td {
37
+ padding: 0 5px 7px;
38
+ }
39
+
40
+ div.field,
41
+ div.actions {
42
+ margin-bottom: 10px;
43
+ }
44
+
45
+ #notice {
46
+ color: green;
47
+ }
48
+
49
+ .field_with_errors {
50
+ padding: 2px;
51
+ background-color: red;
52
+ display: table;
53
+ }
54
+
55
+ #error_explanation {
56
+ width: 450px;
57
+ border: 2px solid red;
58
+ padding: 7px 7px 0;
59
+ margin-bottom: 20px;
60
+ background-color: #f0f0f0;
61
+ }
62
+
63
+ #error_explanation h2 {
64
+ text-align: left;
65
+ font-weight: bold;
66
+ padding: 5px 5px 5px 15px;
67
+ font-size: 12px;
68
+ margin: -7px -7px 0;
69
+ background-color: #c00;
70
+ color: #fff;
71
+ }
72
+
73
+ #error_explanation ul li {
74
+ font-size: 12px;
75
+ list-style: square;
76
+ }
77
+
78
+ label {
79
+ display: block;
80
+ }
@@ -0,0 +1,23 @@
1
+ module Maeku
2
+ class ApplicationController < ::ApplicationController
3
+ protect_from_forgery with: :exception
4
+
5
+ helper_method :current_author?
6
+
7
+ private
8
+
9
+ def current_author
10
+ if respond_to? :current_user
11
+ current_user
12
+ elsif Maeku.current_author
13
+ Maeku.current_author
14
+ else
15
+ raise I18n.t 'controller.application.current_author.not_implemented'
16
+ end
17
+ end
18
+
19
+ def current_author?
20
+ @entry.author_id == current_author.id if @entry
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,71 @@
1
+ require_dependency "maeku/application_controller"
2
+
3
+ module Maeku
4
+ class EntriesController < ApplicationController
5
+ before_action :set_entry, only: [:show, :edit, :update, :destroy]
6
+
7
+ def index
8
+ @entries = current_author.entries
9
+ end
10
+
11
+ def show
12
+ end
13
+
14
+ def new
15
+ @entry = Entry.new
16
+ end
17
+
18
+ def edit
19
+ unless current_author?
20
+ flash[:error] = I18n.t 'controller.entries.edit.error'
21
+ redirect_to entries_url
22
+ end
23
+ end
24
+
25
+ def create
26
+ @entry = Entry.new(entry_params)
27
+ @entry.author_id = current_author.id
28
+
29
+ if @entry.save
30
+ flash[:notice] = I18n.t 'controller.entries.create.success'
31
+ redirect_to @entry
32
+ else
33
+ flash[:error] = I18n.t 'controller.entries.create.error'
34
+ render :new
35
+ end
36
+ end
37
+
38
+ def update
39
+ if @entry.update(entry_params) && current_author?
40
+ flash[:notice] = I18n.t 'controller.entries.update.success'
41
+ redirect_to @entry
42
+ else
43
+ flash[:error] = I18n.t 'controller.entries.update.error'
44
+ render :edit
45
+ end
46
+ end
47
+
48
+ def destroy
49
+ @entry = Entry.find(params[:id])
50
+ if current_author?
51
+ @entry.destroy
52
+ flash[:notice] = I18n.t 'controller.entries.destroy.success'
53
+ redirect_to entries_url
54
+ else
55
+ flash[:error] = I18n.t 'controller.entries.destroy.error'
56
+ redirect_to entries_url
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def entry_params
63
+ params.require(:entry).permit(:entry, :author_id)
64
+ end
65
+
66
+ def set_entry
67
+ @entry = Entry.find(params[:id])
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,4 @@
1
+ module Maeku
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Maeku
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module Maeku
2
+ module AuthorMethods
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_many :entries, foreign_key: "author_id", class_name: "Maeku::Entry", dependent: :destroy
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Maeku
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Maeku
2
+ class Entry < ApplicationRecord
3
+ belongs_to :author, class_name: Maeku.author_class.to_s
4
+ validates :entry, presence: true
5
+ validates :author_id, presence: true
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Maeku</title>
5
+ <%= stylesheet_link_tag "journal/application", media: "all" %>
6
+ <%= javascript_include_tag "journal/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <% if flash %>
11
+ <% flash.each do |key, value| %>
12
+ <div class="alert alert-<%= key %>"><%= value %></div>
13
+ <% end %>
14
+ <% end %>
15
+ <%= yield %>
16
+ </body>
17
+ </html>
@@ -0,0 +1,27 @@
1
+ <%= form_with(model: entry, local: true) do |form| %>
2
+ <% if entry.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2>
5
+ <%= concat(
6
+ pluralize(entry.errors.count, "error"),
7
+ I18n.t('view.before_error_list')
8
+ ) %>
9
+ </h2>
10
+
11
+ <ul>
12
+ <% entry.errors.full_messages.each do |message| %>
13
+ <li><%= message %></li>
14
+ <% end %>
15
+ </ul>
16
+ </div>
17
+ <% end %>
18
+
19
+ <div class="field">
20
+ <%= form.label :entry %>
21
+ <%= form.text_area :entry, id: :entry_entry %>
22
+ </div>
23
+
24
+ <div class="actions">
25
+ <%= form.submit %>
26
+ </div>
27
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <%= flash[:notice] %>
2
+
3
+ <h1>Editing Entry</h1>
4
+
5
+ <%= render 'form', entry: @entry %>
6
+
7
+ <%= link_to 'Show', @entry %>
8
+ <%= link_to 'Destroy', @entry, method: :delete, data: { confirm: 'Are you sure?' } %>
9
+ <%= link_to 'Back', entries_path %>
@@ -0,0 +1,24 @@
1
+ <h1>Entries</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Entry</th>
7
+ <th colspan="3"></th>
8
+ </tr>
9
+ </thead>
10
+
11
+ <tbody>
12
+ <% @entries.each do |entry| %>
13
+ <tr>
14
+ <td><%= entry.entry %></td>
15
+ <td><%= link_to 'Show', entry %></td>
16
+ <td><%= link_to 'Edit', edit_entry_path(entry) if current_author? %></td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
21
+
22
+ <br>
23
+
24
+ <%= link_to 'New Entry', new_entry_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New Entry</h1>
2
+
3
+ <%= render 'form', entry: @entry %>
4
+
5
+ <%= link_to 'Back', entries_path %>
@@ -0,0 +1,7 @@
1
+ <p>
2
+ <strong>Entry:</strong>
3
+ <%= @entry.entry %>
4
+ </p>
5
+
6
+ <%= link_to 'Edit', edit_entry_path(@entry) if current_author? %>
7
+ <%= link_to 'Back', entries_path %>
@@ -0,0 +1,23 @@
1
+ en:
2
+ controller:
3
+ application:
4
+ current_author:
5
+ not_implemented: >
6
+ Your application requires a 'current_user' method. If you use an
7
+ authentication gem like 'devise', this method is provided for you.
8
+ Your user model should also include the module `Maeku::AuthorMethods`
9
+ to be compatible with `maeku_core`.
10
+ entries:
11
+ create:
12
+ error: Entry could not be created. Contact the site administrator.
13
+ success: Entry was successfully created.
14
+ destroy:
15
+ error: Entry could not be destroyed. Contact the site administrator.
16
+ success: Entry was successfully destroyed.
17
+ edit:
18
+ error: You do not have permission to edit this entry.
19
+ update:
20
+ error: Entry could not be updated. Contact the site administrator.
21
+ success: Entry was successfully updated.
22
+ view:
23
+ before_error_list: prohibited this entry from being saved:
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Maeku::Engine.routes.draw do
2
+ resources :entries
3
+ end
@@ -0,0 +1,9 @@
1
+ class CreateMaekuEntries < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :maeku_entries do |t|
4
+ t.text :entry
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class AddAuthorIdToMaekuEntries < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :maeku_entries, :author_id, :integer
4
+ change_column :maeku_entries, :author_id, :integer, null: false
5
+ end
6
+ end
data/lib/maeku.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "maeku/engine"
2
+
3
+ module Maeku
4
+ mattr_accessor :author_class
5
+ mattr_accessor :current_author
6
+
7
+ def self.author_class
8
+ @@author_class.to_s.constantize
9
+ end
10
+
11
+ def self.current_author
12
+ @@current_author.to_s.constantize
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Maeku
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Maeku
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Maeku
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :maeku do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maeku_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Willems
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.11
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.11
41
+ description: A journal for all of your thoughts and feelings.
42
+ email:
43
+ - bw@benjaminwil.info
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Rakefile
49
+ - app/assets/config/maeku_manifest.js
50
+ - app/assets/javascripts/maeku/application.js
51
+ - app/assets/javascripts/maeku/entries.js
52
+ - app/assets/stylesheets/maeku/application.css
53
+ - app/assets/stylesheets/maeku/entries.css
54
+ - app/assets/stylesheets/scaffold.css
55
+ - app/controllers/maeku/application_controller.rb
56
+ - app/controllers/maeku/entries_controller.rb
57
+ - app/jobs/maeku/application_job.rb
58
+ - app/mailers/maeku/application_mailer.rb
59
+ - app/models/concerns/maeku/author_methods.rb
60
+ - app/models/maeku/application_record.rb
61
+ - app/models/maeku/entry.rb
62
+ - app/views/layouts/maeku/application.html.erb
63
+ - app/views/maeku/entries/_form.html.erb
64
+ - app/views/maeku/entries/edit.html.erb
65
+ - app/views/maeku/entries/index.html.erb
66
+ - app/views/maeku/entries/new.html.erb
67
+ - app/views/maeku/entries/show.html.erb
68
+ - config/locales/en.yml
69
+ - config/routes.rb
70
+ - db/migrate/20180311204920_create_maeku_entries.rb
71
+ - db/migrate/20180311212204_add_author_id_to_maeku_entries.rb
72
+ - lib/maeku.rb
73
+ - lib/maeku/engine.rb
74
+ - lib/maeku/version.rb
75
+ - lib/tasks/maeku_tasks.rake
76
+ homepage: https://github.com/maeku/maeku
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.7.6
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A Ruby on Rails-based journalling platform.
100
+ test_files: []