micro_cms 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30b5c1e55c3ca21195b3f9564e0d2b5a56b499450b349167469f345aa5a49485
4
- data.tar.gz: bf95432f342ceedff1dfe24da3eeda9d41e24d7bd2874172bce099a4c836e903
3
+ metadata.gz: 9c07cc5c21d44d0bde6dfa7bde4e7b5688e7b91d89dde60cf0bdd0fd6e9f9968
4
+ data.tar.gz: fc83030b2ec6e131e1e06c7973cc310646494ebcdcc000e1445502231123a721
5
5
  SHA512:
6
- metadata.gz: bf74071bb121573869b82a8c90dc6f8ef13feb0fdd26394f8e53dbe66a17cf2d9b76f10bedb4b2787f073dca0828334f91e80bfeb379f66d4a9891e5c7e042bb
7
- data.tar.gz: 51db9356c673799b72531e960520ae7b9c86747a41e28224ef438f2dca2fdca873fc350e424089b2caa2efb0206f864fc5659f4ba1001609100ae5920f7bcf05
6
+ metadata.gz: dc5e6115395ff2ecf1f73cf4858eebd16278577d4e6429abd1ed3588c1ed48bf6ee8e0294b45e5ab4d83d688f5b6ec9986133b8c20a6378b785ffbb9f881e4ab
7
+ data.tar.gz: e4a8ddbfd248205257603b2da075bebf683f7eaa4fee68e458ba3e63c969aa81a08444d81fd88d566219afcd6eb7b8c77528a6fd121154a568461604c5f36612
data/README.md CHANGED
@@ -54,13 +54,46 @@ bin/rails db:migrate
54
54
  ```
55
55
  to copy the migrations.
56
56
 
57
- Require the JavaScript (e.g. `//= require micro_cms`) and all styles (e.g. `@import 'micro_cms';'`).
58
-
59
57
  Mount the engine routes in you `config/routes.rb` file:
60
58
  ```ruby
61
59
  mount MicroCms::Engine => '/micro_cms'
62
60
  ```
63
61
 
62
+ ### Usage with Sprockets
63
+
64
+ Require the JavaScript (e.g. `//= require micro_cms`) and all styles (e.g. `@import 'micro_cms';'`).
65
+
66
+ ### Usage with Webpacker
67
+
68
+ Make sure that you import `rails/ujs` like that in your `application.js`:
69
+
70
+ ```js
71
+ import Rails from '@rails/ujs';
72
+ Rails.start();
73
+ ...
74
+ window.Rails = Rails;
75
+ ```
76
+
77
+ The last line makes the Rails scope global (since we inline the script, this is needed).
78
+
79
+ Now you have to include the helper to your ApplicationHelper:
80
+
81
+ ```rb
82
+ module ApplicationHelper
83
+ include MicroCms::ApplicationHelper
84
+ ...
85
+ end
86
+ ```
87
+
88
+ Now you can use the helper to inline the needed scripts via `app/views/layouts/application.html.slim`. It's strongly
89
+ recommended to check first, if the user is allowed to edit (but this is not part of this gem):
90
+
91
+ ```rb
92
+ - if user_signed_in? # not part of this gem!
93
+ = micro_cms_asset_tags
94
+ ```
95
+
96
+
64
97
  ## Configuration
65
98
  `app/config/initializers/micro_cms.rb`:
66
99
 
@@ -31,6 +31,7 @@
31
31
  dataType: 'json',
32
32
  contentType: 'multipart/form-data',
33
33
  data: data,
34
+ beforeSend: function() { return true; },
34
35
  success: function(e) {
35
36
  blink('successful');
36
37
  },
@@ -2,5 +2,19 @@
2
2
 
3
3
  module MicroCms
4
4
  module ApplicationHelper
5
+ # rubocop:disable Rails/OutputSafety
6
+ def micro_cms_asset_tags
7
+ js = load_gem_file 'micro_cms', 'app/assets/javascripts/micro_cms.js'
8
+ css = load_gem_file 'micro_cms', 'app/assets/stylesheets/micro_cms/micro_cms.css'
9
+ tag.script(js.html_safe) + tag.style(css)
10
+ end
11
+ # rubocop:enable Rails/OutputSafety
12
+
13
+ private
14
+
15
+ def load_gem_file(gem_name, assets_path)
16
+ path = File.join(Gem.loaded_specs[gem_name].full_gem_path, assets_path)
17
+ File.read(path)
18
+ end
5
19
  end
6
20
  end
@@ -1,8 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ begin
4
+ require 'factory_bot_rails'
5
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
6
+ end
7
+
3
8
  module MicroCms
4
9
  class Engine < ::Rails::Engine
10
+ FACTORIES = File.expand_path('../../spec/factories', __dir__).freeze
11
+
5
12
  isolate_namespace MicroCms
13
+ config.autoload_once_paths << "#{root}/app/helpers"
6
14
 
7
15
  config.generators do |generators|
8
16
  generators.test_framework :rspec
@@ -12,7 +20,7 @@ module MicroCms
12
20
 
13
21
  initializer 'micro_cms.include_view_helpers' do |_app|
14
22
  ActiveSupport.on_load :action_view do
15
- ActionView::Base.public_send :include, MicroCms::CmsBlockHelper
23
+ include MicroCms::CmsBlockHelper
16
24
  end
17
25
  end
18
26
 
@@ -21,5 +29,11 @@ module MicroCms
21
29
  config.authorization_token = SecureRandom.urlsafe_base64
22
30
  end
23
31
  end
32
+
33
+ if defined? FactoryBotRails
34
+ initializer 'mirco_cms.set_factory_paths', after: 'factory_bot.set_factory_paths' do |_app|
35
+ FactoryBot.definition_file_paths << FACTORIES
36
+ end
37
+ end
24
38
  end
25
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MicroCms
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
Binary file
@@ -1 +0,0 @@
1
-  (1.7ms) SELECT sqlite_version(*)