solidus_content 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +72 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +20 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +38 -0
  8. data/Gemfile +38 -0
  9. data/LICENSE +26 -0
  10. data/README.md +439 -0
  11. data/Rakefile +6 -0
  12. data/app/assets/javascripts/spree/backend/solidus_content.js +2 -0
  13. data/app/assets/javascripts/spree/frontend/solidus_content.js +2 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_content.css +4 -0
  15. data/app/assets/stylesheets/spree/frontend/solidus_content.css +4 -0
  16. data/app/controllers/solidus_content/resource_controller.rb +35 -0
  17. data/app/controllers/spree/admin/entries_controller.rb +25 -0
  18. data/app/controllers/spree/admin/entry_types_controller.rb +25 -0
  19. data/app/controllers/spree/solidus_content_controller.rb +13 -0
  20. data/app/models/solidus_content/application_record.rb +5 -0
  21. data/app/models/solidus_content/entry.rb +44 -0
  22. data/app/models/solidus_content/entry_type.rb +55 -0
  23. data/app/models/solidus_content/provider/fields.rb +20 -0
  24. data/app/views/spree/admin/entries/_form.html.erb +31 -0
  25. data/app/views/spree/admin/entries/_options_form.html.erb +18 -0
  26. data/app/views/spree/admin/entries/edit.html.erb +16 -0
  27. data/app/views/spree/admin/entries/index.html.erb +54 -0
  28. data/app/views/spree/admin/entries/new.html.erb +21 -0
  29. data/app/views/spree/admin/entry_types/_form.html.erb +30 -0
  30. data/app/views/spree/admin/entry_types/_options_form.html.erb +16 -0
  31. data/app/views/spree/admin/entry_types/edit.html.erb +16 -0
  32. data/app/views/spree/admin/entry_types/index.html.erb +54 -0
  33. data/app/views/spree/admin/entry_types/new.html.erb +21 -0
  34. data/app/views/spree/admin/shared/_solidus_content_sub_menu.html.erb +9 -0
  35. data/bin/console +17 -0
  36. data/bin/rails +7 -0
  37. data/bin/rails-engine +13 -0
  38. data/bin/rails-sandbox +16 -0
  39. data/bin/rake +7 -0
  40. data/bin/rspec +7 -0
  41. data/bin/sandbox +84 -0
  42. data/bin/setup +8 -0
  43. data/config/initializers/spree.rb +12 -0
  44. data/config/locales/en.yml +51 -0
  45. data/config/routes.rb +14 -0
  46. data/db/migrate/20200207135842_create_solidus_content_entries.rb +11 -0
  47. data/db/migrate/20200306110114_create_solidus_content_entry_types.rb +12 -0
  48. data/lib/generators/solidus_content/install/install_generator.rb +36 -0
  49. data/lib/generators/solidus_content/install/templates/initializer.rb +20 -0
  50. data/lib/solidus_content.rb +10 -0
  51. data/lib/solidus_content/active_record.rb +7 -0
  52. data/lib/solidus_content/configuration.rb +38 -0
  53. data/lib/solidus_content/engine.rb +19 -0
  54. data/lib/solidus_content/factories.rb +13 -0
  55. data/lib/solidus_content/providers.rb +23 -0
  56. data/lib/solidus_content/providers/contentful.rb +36 -0
  57. data/lib/solidus_content/providers/json.rb +27 -0
  58. data/lib/solidus_content/providers/prismic.rb +36 -0
  59. data/lib/solidus_content/providers/raw.rb +22 -0
  60. data/lib/solidus_content/providers/solidus_static_content.rb +23 -0
  61. data/lib/solidus_content/providers/yaml.rb +33 -0
  62. data/lib/solidus_content/version.rb +5 -0
  63. data/solidus_content.gemspec +36 -0
  64. data/spec/features/admin/content/create_entry_spec.rb +36 -0
  65. data/spec/features/admin/content/create_entry_type_spec.rb +36 -0
  66. data/spec/features/admin/content/delete_entry_spec.rb +20 -0
  67. data/spec/features/admin/content/delete_entry_type_spec.rb +20 -0
  68. data/spec/features/admin/content/edit_entry_spec.rb +45 -0
  69. data/spec/features/admin/content/edit_entry_type_spec.rb +44 -0
  70. data/spec/features/admin/content/list_entries_spec.rb +33 -0
  71. data/spec/features/admin/content/list_entry_types_spec.rb +33 -0
  72. data/spec/features/admin/sidebar_spec.rb +19 -0
  73. data/spec/features/render_content_with_views_spec.rb +41 -0
  74. data/spec/fixtures/content/example.json +1 -0
  75. data/spec/fixtures/content/example.yaml +1 -0
  76. data/spec/fixtures/content/example.yml +1 -0
  77. data/spec/fixtures/content/example_2.yaml +1 -0
  78. data/spec/models/solidus_content/entry_spec.rb +100 -0
  79. data/spec/models/solidus_content/entry_type_spec.rb +106 -0
  80. data/spec/solidus_content/configuration_spec.rb +37 -0
  81. data/spec/solidus_content/providers/contentful_spec.rb +56 -0
  82. data/spec/solidus_content/providers/json_spec.rb +33 -0
  83. data/spec/solidus_content/providers/prismic_spec.rb +82 -0
  84. data/spec/solidus_content/providers/solidus_static_content_spec.rb +34 -0
  85. data/spec/solidus_content/providers/yaml_spec.rb +51 -0
  86. data/spec/solidus_content_spec.rb +23 -0
  87. data/spec/spec_helper.rb +32 -0
  88. data/spec/support/warden.rb +5 -0
  89. metadata +206 -0
@@ -0,0 +1,16 @@
1
+ <% admin_breadcrumb link_to(plural_resource_name(model_class), spree.admin_entry_types_path) %>
2
+ <% admin_breadcrumb @entry_type.name %>
3
+
4
+ <%= render 'spree/shared/error_messages', target: @object %>
5
+
6
+ <%= form_for @entry_type, url: spree.admin_entry_type_path(@entry_type) do |form| %>
7
+ <fieldset data-hook="edit_entry_type">
8
+ <%= content_tag :legend, model_class.model_name.human %>
9
+ <%= render 'form', form: form %>
10
+
11
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
12
+ <%= submit_tag t('spree.actions.update'), class: 'btn btn-primary' %>
13
+ <%= link_to t('spree.actions.cancel'), collection_url, class: 'button' %>
14
+ </div>
15
+ </fieldset>
16
+ <% end %>
@@ -0,0 +1,54 @@
1
+ <% admin_layout "full-width" %>
2
+
3
+ <% admin_breadcrumb plural_resource_name(model_class) %>
4
+
5
+ <% content_for :page_actions do %>
6
+ <li>
7
+ <%= link_to t('spree.admin.entry_type.new'), new_object_url, class: 'btn btn-primary' %>
8
+ </li>
9
+ <% end if can?(:create, model_class) %>
10
+
11
+ <%= paginate @collection, theme: "solidus_admin" %>
12
+
13
+ <% if @collection.any? %>
14
+ <table class="index" id="listing_entry_types">
15
+ <colgroup>
16
+ <col style="width: 40%;">
17
+ <col style="width: 40%;">
18
+ <col style="width: 20%;">
19
+ </colgroup>
20
+ <thead>
21
+ <tr data-hook="admin_products_index_headers">
22
+ <th><%= model_class.human_attribute_name(:name) %></th>
23
+ <th><%= model_class.human_attribute_name(:provider) %></th>
24
+ <th></th>
25
+ </tr>
26
+ </thead>
27
+ <tbody>
28
+ <% @collection.each do |entry_type| %>
29
+ <tr id="<%= spree_dom_id entry_type %>" data-hook="admin_entry_types_index_rows">
30
+ <td>
31
+ <%= link_to entry_type.name, object_url(entry_type) %>
32
+ </td>
33
+ <td>
34
+ <%= entry_type.provider_name %>
35
+ </td>
36
+ <td class="actions" data-hook="admin_entry_types_index_row_actions">
37
+ <%= link_to_edit entry_type, url: edit_object_url(entry_type),
38
+ class: 'edit edit-entry-type' if can?(:update, entry_type) %>
39
+ <%= link_to_delete entry_type, url: object_url(entry_type),
40
+ class: 'trash delete-entry-type' if can?(:destroy, entry_type) %>
41
+ </td>
42
+ </tr>
43
+ <% end %>
44
+ </tbody>
45
+ </table>
46
+ <% else %>
47
+ <div class="no-objects-found">
48
+ <%= render 'spree/admin/shared/no_objects_found',
49
+ resource: model_class,
50
+ new_resource_url: new_object_url %>
51
+ </div>
52
+ <% end %>
53
+
54
+ <%= paginate @collection, theme: "solidus_admin" %>
@@ -0,0 +1,21 @@
1
+ <% admin_breadcrumb link_to(plural_resource_name(model_class), collection_url) %>
2
+ <% admin_breadcrumb "#{t('spree.actions.new')} #{model_class.model_name.human}" %>
3
+
4
+
5
+ <%= render 'spree/shared/error_messages', target: @object %>
6
+
7
+ <%= form_for @object, url: collection_url do |form| %>
8
+ <fieldset data-hook="new_entry_type">
9
+ <legend align="center">
10
+ <%= admin_hint nil, t('solidus_content.hints.new_entry_type') %>
11
+ <%= t('new', scope: %w[spree admin entry_type]) %>
12
+ </legend>
13
+
14
+ <%= render 'form', form: form %>
15
+
16
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
17
+ <%= submit_tag t('spree.actions.create'), class: 'btn btn-primary' %>
18
+ <%= link_to t('spree.actions.cancel'), collection_url, class: 'button' %>
19
+ </div>
20
+ </fieldset>
21
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <ul class="admin-subnav" data-hook="admin_settings_sub_tabs">
2
+ <% if can?(:admin, SolidusContent::EntryType) %>
3
+ <%= tab :entry_types, url: spree.admin_entry_types_path %>
4
+ <% end %>
5
+
6
+ <% if can?(:admin, SolidusContent::Entry) %>
7
+ <%= tab :entries, url: spree.admin_entries_path %>
8
+ <% end %>
9
+ </ul>
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_content"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if %w[g generate].include? ARGV.first
4
+ exec "#{__dir__}/rails-engine", *ARGV
5
+ else
6
+ exec "#{__dir__}/rails-sandbox", *ARGV
7
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/solidus_content/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = 'sandbox'
4
+
5
+ unless File.exist? "#{app_root}/bin/rails"
6
+ warn 'Creating the sandbox app...'
7
+ Dir.chdir "#{__dir__}/.." do
8
+ system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
9
+ warn 'Automatic creation of the sandbox app failed'
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir.chdir app_root
16
+ exec 'bin/rails', *ARGV
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ case "$DB" in
6
+ postgres|postgresql)
7
+ RAILSDB="postgresql"
8
+ ;;
9
+ mysql)
10
+ RAILSDB="mysql"
11
+ ;;
12
+ sqlite|'')
13
+ RAILSDB="sqlite3"
14
+ ;;
15
+ *)
16
+ echo "Invalid DB specified: $DB"
17
+ exit 1
18
+ ;;
19
+ esac
20
+
21
+ if [ ! -z $SOLIDUS_BRANCH ]
22
+ then
23
+ BRANCH=$SOLIDUS_BRANCH
24
+ else
25
+ BRANCH="master"
26
+ fi
27
+
28
+ extension_name="solidus_content"
29
+
30
+ # Stay away from the bundler env of the containing extension.
31
+ function unbundled {
32
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
33
+ }
34
+
35
+ rm -rf ./sandbox
36
+ unbundled bundle exec rails new sandbox --database="$RAILSDB" \
37
+ --skip-bundle \
38
+ --skip-git \
39
+ --skip-keeps \
40
+ --skip-rc \
41
+ --skip-spring \
42
+ --skip-test \
43
+ --skip-javascript
44
+
45
+ if [ ! -d "sandbox" ]; then
46
+ echo 'sandbox rails application failed'
47
+ exit 1
48
+ fi
49
+
50
+ cd ./sandbox
51
+ cat <<RUBY >> Gemfile
52
+ gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
53
+ gem 'solidus_auth_devise', '>= 2.1.0'
54
+ gem 'rails-i18n'
55
+ gem 'solidus_i18n'
56
+
57
+ gem '$extension_name', path: '..'
58
+
59
+ group :test, :development do
60
+ platforms :mri do
61
+ gem 'pry-byebug'
62
+ end
63
+ end
64
+ RUBY
65
+
66
+ unbundled bundle install --gemfile Gemfile
67
+
68
+ unbundled bundle exec rake db:drop db:create
69
+
70
+ unbundled bundle exec rails generate spree:install \
71
+ --auto-accept \
72
+ --user_class=Spree::User \
73
+ --enforce_available_locales=true \
74
+ --with-authentication=false \
75
+ $@
76
+
77
+ unbundled bundle exec rails generate solidus:auth:install
78
+
79
+ echo
80
+ echo "🚀 Sandbox app successfully created for $extension_name!"
81
+ echo "🚀 Using $RAILSDB and Solidus $BRANCH"
82
+ echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
83
+ echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
84
+ echo "🚀 This app is intended for test purposes."
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bin/rake clobber
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Backend::Config.configure do |config|
4
+ config.menu_items << config.class::MenuItem.new(
5
+ [:entry_types, :entries],
6
+ 'text-width',
7
+ condition: -> { can?(:admin, SolidusContent::EntryType) },
8
+ label: :content,
9
+ partial: 'spree/admin/shared/solidus_content_sub_menu',
10
+ url: :admin_entry_types_path
11
+ )
12
+ end
@@ -0,0 +1,51 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ spree:
6
+ admin:
7
+ tab:
8
+ content: Content
9
+ entry_types: Types
10
+ entries: Entries
11
+ entry_type:
12
+ new: New type
13
+ entry:
14
+ new: New entry
15
+ hints:
16
+ solidus_content/entry:
17
+ slug: |
18
+ The slug will be the handle used in either the url or to retrieve
19
+ the entry. The "default" value is used when the slug doesn't matter
20
+ and you have just one entry of that type.
21
+ entry_type: |
22
+ Select the type of content you want to create.
23
+ solidus_content/entry_type:
24
+ provider_name: |
25
+ The provider can only be selected during creation, once selected you
26
+ won't be able to change it.
27
+ activerecord:
28
+ attributes:
29
+ solidus_content/entry:
30
+ entry_type: Type
31
+ solidus_content/entry_type:
32
+ provider_name: Provider
33
+ errors:
34
+ models:
35
+ solidus_content/entry_type:
36
+ attributes:
37
+ provider_name:
38
+ readonly: "can't be changed"
39
+ solidus_content:
40
+ providers:
41
+ raw: Raw
42
+ json: JSON
43
+ yaml: YAML
44
+ contentful: Contentful
45
+ prismic: Prismic
46
+ solidus_static_content: SolidusStaticContent
47
+ hints:
48
+ new_entry_type: |
49
+ Use an entry-type to group content that shares the same structure.
50
+ For example a list of editorials that all have a title and a body should
51
+ belong to a single entry-type named "editorial".
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Core::Engine.routes.draw do
4
+ unless SolidusContent.config.skip_default_route
5
+ get '/c/:type(/:id)', to: 'solidus_content#show', id: :default, as: :solidus_content
6
+ end
7
+
8
+ namespace :admin do
9
+ scope path: "content" do
10
+ resources :entry_types, path: "types"
11
+ resources :entries
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSolidusContentEntries < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :solidus_content_entries do |t|
4
+ t.references :entry_type, null: false
5
+ t.json :options, null: false
6
+ t.string :slug, null: false, default: :default
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateSolidusContentEntryTypes < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :solidus_content_entry_types do |t|
4
+ t.string :name, null: false
5
+ t.json :options, null: false
6
+ t.string :provider_name, null: false
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :solidus_content_entry_types, :name
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusContent
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ class_option :auto_run_migrations, type: :boolean, default: false
7
+
8
+ def add_javascripts
9
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_content\n" # rubocop:disable Metrics/LineLength
10
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_content\n" # rubocop:disable Metrics/LineLength
11
+ end
12
+
13
+ def add_stylesheets
14
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_content\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength
15
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_content\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength
16
+ end
17
+
18
+ def add_migrations
19
+ run 'bin/rails railties:install:migrations FROM=solidus_content'
20
+ end
21
+
22
+ def run_migrations
23
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Metrics/LineLength
24
+ if run_migrations
25
+ run 'bin/rails db:migrate'
26
+ else
27
+ puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
28
+ end
29
+ end
30
+
31
+ def copy_initializer
32
+ copy_file 'initializer.rb', 'config/initializers/solidus_content.rb'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusContent.configure do |config|
4
+ # You can control the list of content providers that will be available to the
5
+ # backend.
6
+ #
7
+ # config.providers.delete :prismic
8
+
9
+ # Define a custom content provider.
10
+ #
11
+ # config.register_provider :data_dir, ->(input) {
12
+ # data = YAML.load(Rails.root.join('data', input[:slug] + '.yml').read)
13
+ # input.merge(data: data)
14
+ # }
15
+
16
+ # Set to `true` to register your own route, instead of using the default
17
+ # that starts with `/c/`.
18
+ #
19
+ # config.skip_default_route = true
20
+ end