inscribe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/inscribe/application.js +13 -0
  5. data/app/assets/javascripts/inscribe/snippets.js +2 -0
  6. data/app/assets/stylesheets/inscribe/application.css +15 -0
  7. data/app/assets/stylesheets/inscribe/snippets.css +4 -0
  8. data/app/assets/stylesheets/scaffold.css +56 -0
  9. data/app/controllers/inscribe/application_controller.rb +4 -0
  10. data/app/controllers/inscribe/snippets_controller.rb +62 -0
  11. data/app/helpers/inscribe/application_helper.rb +4 -0
  12. data/app/helpers/inscribe/snippets_helper.rb +27 -0
  13. data/app/models/inscribe/snippet.rb +57 -0
  14. data/app/views/inscribe/snippets/_form.html.erb +33 -0
  15. data/app/views/inscribe/snippets/edit.html.erb +6 -0
  16. data/app/views/inscribe/snippets/index.html.erb +31 -0
  17. data/app/views/inscribe/snippets/new.html.erb +5 -0
  18. data/app/views/inscribe/snippets/show.html.erb +24 -0
  19. data/app/views/layouts/inscribe/application.html.erb +14 -0
  20. data/config/routes.rb +4 -0
  21. data/db/migrate/20150127195645_create_inscribe_snippets.rb +12 -0
  22. data/lib/inscribe.rb +4 -0
  23. data/lib/inscribe/engine.rb +5 -0
  24. data/lib/inscribe/version.rb +3 -0
  25. data/lib/tasks/inscribe_tasks.rake +8 -0
  26. data/test/controllers/inscribe/snippets_controller_test.rb +51 -0
  27. data/test/dummy/README.rdoc +28 -0
  28. data/test/dummy/Rakefile +6 -0
  29. data/test/dummy/app/assets/javascripts/application.js +13 -0
  30. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  31. data/test/dummy/app/controllers/application_controller.rb +7 -0
  32. data/test/dummy/app/controllers/home_controller.rb +4 -0
  33. data/test/dummy/app/helpers/application_helper.rb +2 -0
  34. data/test/dummy/app/views/home/index.html.erb +3 -0
  35. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/test/dummy/bin/bundle +3 -0
  37. data/test/dummy/bin/rails +4 -0
  38. data/test/dummy/bin/rake +4 -0
  39. data/test/dummy/config.ru +4 -0
  40. data/test/dummy/config/application.rb +23 -0
  41. data/test/dummy/config/boot.rb +5 -0
  42. data/test/dummy/config/database.yml +25 -0
  43. data/test/dummy/config/environment.rb +5 -0
  44. data/test/dummy/config/environments/development.rb +37 -0
  45. data/test/dummy/config/environments/production.rb +78 -0
  46. data/test/dummy/config/environments/test.rb +39 -0
  47. data/test/dummy/config/initializers/assets.rb +8 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  50. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/test/dummy/config/initializers/inflections.rb +16 -0
  52. data/test/dummy/config/initializers/mime_types.rb +4 -0
  53. data/test/dummy/config/initializers/session_store.rb +3 -0
  54. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  55. data/test/dummy/config/locales/en.yml +23 -0
  56. data/test/dummy/config/routes.rb +5 -0
  57. data/test/dummy/config/secrets.yml +22 -0
  58. data/test/dummy/db/development.sqlite3 +0 -0
  59. data/test/dummy/db/schema.rb +25 -0
  60. data/test/dummy/log/development.log +1363 -0
  61. data/test/dummy/public/404.html +67 -0
  62. data/test/dummy/public/422.html +67 -0
  63. data/test/dummy/public/500.html +66 -0
  64. data/test/dummy/public/favicon.ico +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/0a10459c4e57397f1a896088f3c14d1b +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/0bdd305582b5effa500303a7a906e208 +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/0f3d759ebbc95302d8be4d6dd0ec3271 +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/1c6d4a59c3c14ddb282ed62ab610bbc0 +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sprockets/4dea50a64e233565790cb9f9fa7edf30 +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/56f753f992945dc5fa08c48b60868b9f +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/587cbe72e5ccb2b352f19b7c5c026d42 +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/842ca623328b19c3ad6701ee97de29e1 +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/883d03c9fd545f15efe23b3864da2ac8 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/94fff90a9b9315bcd02e0c4a6fc5d9e3 +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/bb88c11fb59c95c429f50cd19d47eb54 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/e91328930f222cdb20b0dae0cdfecb94 +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  83. data/test/fixtures/inscribe/snippets.yml +13 -0
  84. data/test/helpers/inscribe/snippets_helper_test.rb +6 -0
  85. data/test/inscribe_test.rb +7 -0
  86. data/test/integration/navigation_test.rb +10 -0
  87. data/test/models/inscribe/snippet_test.rb +9 -0
  88. data/test/test_helper.rb +19 -0
  89. metadata +251 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99d2808d6732597702d8c63e78b1250c0ba2395c
4
+ data.tar.gz: caa6213903eaebf80aea0e900d75ef4216212449
5
+ SHA512:
6
+ metadata.gz: f244f5a3fceb1d75e1aaf11d60d56adddd748486bf912659a88f206e35ea5e1a1d0591624307daadd2d6e48e3084923412a14b0eb9738ea13fe0b6d2b14a1f70
7
+ data.tar.gz: 819ab4295d951e27961e4d8b420b5a26e310d305497e283f788850675c0748b6c48e5ad20236d46cff96444849217f5d366c2f1e993d41389e4a9864f77f8993
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
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 = 'Inscribe'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
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
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -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 vendor/assets/javascripts of plugins, if any, 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.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/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 vendor/assets/stylesheets of plugins, if any, 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 styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * 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,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ module Inscribe
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "inscribe/application_controller"
2
+
3
+ module Inscribe
4
+ class SnippetsController < ApplicationController
5
+ before_action :set_snippet, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /snippets
8
+ def index
9
+ @snippets = Snippet.all
10
+ end
11
+
12
+ # GET /snippets/1
13
+ def show
14
+ end
15
+
16
+ # GET /snippets/new
17
+ def new
18
+ @snippet = Snippet.new
19
+ end
20
+
21
+ # GET /snippets/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /snippets
26
+ def create
27
+ @snippet = Snippet.new(snippet_params)
28
+
29
+ if @snippet.save
30
+ redirect_to @snippet, notice: 'Snippet was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /snippets/1
37
+ def update
38
+ if @snippet.update(snippet_params)
39
+ redirect_to @snippet, notice: 'Snippet was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /snippets/1
46
+ def destroy
47
+ @snippet.destroy
48
+ redirect_to snippets_url, notice: 'Snippet was successfully destroyed.'
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_snippet
54
+ @snippet = Snippet.find(params[:id])
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def snippet_params
59
+ params.require(:snippet).permit(:view, :key, :value, :value_type)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ module Inscribe
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,27 @@
1
+ module Inscribe
2
+ module SnippetsHelper
3
+ def snippet(key)
4
+ snippets_for_current_page[key].to_s.html_safe
5
+ end
6
+
7
+ def load_snippets(views)
8
+ # The first non-blank data value is returned
9
+ # Order of snippet value goes: value, value_plain, snippet_image.
10
+ # --> Now, we just use snippet.snippet_type to determine
11
+ @snippets_for_current_page ||= begin
12
+ # Always make sure to grab 'global' snippets too
13
+ views_list = Array.new().push(views).push('global')
14
+ Hash[Snippet.where(view: views_list).map{|s| [s.key, format_snippet(s)]}]
15
+ end
16
+ end
17
+
18
+ def snippets_for_current_page
19
+ load_snippets("#{controller_name}/#{action_name}")
20
+ end
21
+
22
+ def format_snippet(s)
23
+ s.
24
+ s.value
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,57 @@
1
+ module Inscribe
2
+ class Snippet < ActiveRecord::Base
3
+ enum snippet_type: [:rich_text, :simple_text, :image]
4
+
5
+ def self.init(locales: nil, verbose: false)
6
+ snippets_file_path = File.join(Rails.root, 'db', 'data', 'snippets.yml')
7
+ puts "Loading snippet defaults from #{snippets_file_path}" if verbose
8
+ snippets = YAML.load(File.read(snippets_file_path))
9
+ locales_to_initialize = locales.nil? ? Locale.all : Array.new([locales]).flatten
10
+ Locale.all.each do |locale|
11
+ Locale.current_id = locale.id
12
+ if verbose
13
+ puts "-" * 40
14
+ puts "Locale '#{locale.name}'"
15
+ end
16
+ snippets.each do |view, snippets_for_view|
17
+ puts view if verbose
18
+ failed_snippets = []
19
+ already_existing_snippets = []
20
+ created_snippets = []
21
+ snippets_for_view.each do |key, snippet|
22
+ existing_snippet = Snippet.find_by(view: view, key: key)
23
+ if existing_snippet.nil?
24
+ new_snippet = Snippet.new(view: view, key: key)
25
+ case snippet['type']
26
+ when 'rich text'
27
+ new_snippet.snippet_type = :rich_text
28
+ new_snippet.value = snippet['value']
29
+ when 'image'
30
+ new_snippet.snippet_type = :image
31
+ new_snippet.save!
32
+ new_snippet.snippet_image.store!(File.open(File.join(Rails.root, 'db', 'data', 'snippet_files', snippet['value'])))
33
+ new_snippet.value_plain = ''
34
+ new_snippet.save
35
+ else
36
+ new_snippet.snippet_type = :simple_text
37
+ new_snippet.value_plain = snippet['value']
38
+ end
39
+ if new_snippet.save
40
+ created_snippets << key
41
+ else
42
+ failed_snippets << key
43
+ end
44
+ else
45
+ already_existing_snippets << key
46
+ end
47
+ end
48
+ if verbose
49
+ puts " Created #{created_snippets.count}: #{created_snippets.join(', ')}" if created_snippets.any?
50
+ puts " Skipped #{already_existing_snippets.count}: #{already_existing_snippets.join(', ')}" if already_existing_snippets.any?
51
+ puts " Failed #{failed_snippets.count}: #{failed_snippets.join(', ')}" if failed_snippets.any?
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,33 @@
1
+ <%= form_for(@snippet) do |f| %>
2
+ <% if @snippet.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@snippet.errors.count, "error") %> prohibited this snippet from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @snippet.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :view %><br>
16
+ <%= f.text_field :view %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :key %><br>
20
+ <%= f.text_field :key %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :value %><br>
24
+ <%= f.text_area :value %>
25
+ </div>
26
+ <div class="field">
27
+ <%= f.label :value_type %><br>
28
+ <%= f.number_field :value_type %>
29
+ </div>
30
+ <div class="actions">
31
+ <%= f.submit %>
32
+ </div>
33
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing snippet</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @snippet %> |
6
+ <%= link_to 'Back', snippets_path %>
@@ -0,0 +1,31 @@
1
+ <h1>Listing snippets</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>View</th>
7
+ <th>Key</th>
8
+ <th>Value</th>
9
+ <th>Value type</th>
10
+ <th colspan="3"></th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @snippets.each do |snippet| %>
16
+ <tr>
17
+ <td><%= snippet.view %></td>
18
+ <td><%= snippet.key %></td>
19
+ <td><%= snippet.value %></td>
20
+ <td><%= snippet.value_type %></td>
21
+ <td><%= link_to 'Show', snippet %></td>
22
+ <td><%= link_to 'Edit', edit_snippet_path(snippet) %></td>
23
+ <td><%= link_to 'Destroy', snippet, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br>
30
+
31
+ <%= link_to 'New Snippet', new_snippet_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New snippet</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', snippets_path %>
@@ -0,0 +1,24 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>View:</strong>
5
+ <%= @snippet.view %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Key:</strong>
10
+ <%= @snippet.key %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Value:</strong>
15
+ <%= @snippet.value %>
16
+ </p>
17
+
18
+ <p>
19
+ <strong>Value type:</strong>
20
+ <%= @snippet.value_type %>
21
+ </p>
22
+
23
+ <%= link_to 'Edit', edit_snippet_path(@snippet) %> |
24
+ <%= link_to 'Back', snippets_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Inscribe</title>
5
+ <%= stylesheet_link_tag "inscribe/application", media: "all" %>
6
+ <%= javascript_include_tag "inscribe/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>