rubyblok 1.0.0 → 1.1.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: '096e822e37774a75693902aff5fe81ccb971ed74d50e849a0b47fa49511642e6'
4
- data.tar.gz: 28ac8e653f9ed908a14be4622883acf6ef29c642d96925c1e84766228a5a0f1d
3
+ metadata.gz: 387e9c3d34367e3cbc2f7bd45bb3c38358e203e009f0d7a79f77c2f0569e590c
4
+ data.tar.gz: 13d329d7a0d6498124ee602b9252722051b4bf6f01e62186cc9c6b61fd26da69
5
5
  SHA512:
6
- metadata.gz: feae7213dc1c38278accc0cc36ec91b903c15ac1087fb598e51551bf87156cdfe0a4eaaef033e7e3ff4c4ecd50a8296b874390c5b93db741b0fe69bda2efa474
7
- data.tar.gz: aa25681967a4c901c4c12c9146db6fd03d3f87ef39de957a47337f66a21cede5edd5b0350b61f9690530f376eb86d2f87d7cc17f2b7ad8c87d1895c95eeedfdf
6
+ metadata.gz: 663185c2a74652136c644306457bb110d5c67290826f100e14c4e033e543f7db68bdb24b1f8d5843d78d20e32760ddc861b8f57abedba05cf9da73092f36041f
7
+ data.tar.gz: b2000c3d50bc5eef358a3b2cffc43cb2e980f89f63cf0b8a8acc7ac83bfc568e3b0440fd0029473a4f3ba792fd9e416d7e85164eafcc03a4677f81e0082239be
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [1.1.0] - 2024-05-02
6
+
7
+ ### Added
8
+ - Hello world generator
9
+
10
+ ## [1.0.0] - 2024-03-27
11
+
12
+ ### Added
13
+ - Initial release
14
+ - Rubyblok helpers
15
+ - Config generator
16
+ - Model generator for caching Storyblok content
17
+ - Webhook controller generator for publishing Storyblok contents
data/README.md CHANGED
@@ -18,15 +18,14 @@ In addition, Rubyblok provides an abstraction layer and stores all your content
18
18
 
19
19
  ## Installation
20
20
  Rubyblok 1.0 works with Rails 6.0 onwards. Run:
21
- ```
21
+ ```bash
22
22
  bundle add rubyblok
23
23
  ```
24
24
 
25
- ### Storyblok account and variables
25
+ ### Storyblok account and new space
26
+ [Click here](https://app.storyblok.com/#/signup) to create a free acount at Storyblok, the CMS platform where you will have access to the visual and real-time content editing.
26
27
 
27
- [Click here](https://app.storyblok.com/?_gl=1*196uoul*_gcl_au*MTg1NjA5NjA0MS4xNzA5MDY5ODk3#!/signup) to create a free acount at Storyblok, the CMS platform where you will have access to the visual and real-time content editing.
28
-
29
- Create a new Space, in _Spaces > Add Space_.
28
+ Create a new Space, in _My Spaces > Add Space_. Select the free Community plan by clicking its "Continue" button and give your space a name.
30
29
 
31
30
  Get your Storyblok API token in your account, at _Storyblok Space > Settings > Access tokens_ page. Copy the "Preview" access level key.
32
31
 
@@ -43,88 +42,45 @@ STORYBLOK_WEBHOOK_SECRET=''
43
42
 
44
43
  ## Getting Started
45
44
 
46
- ### Your first Rubyblok page
47
- Let's get started with Rubyblok by creating our first page.
45
+ ### Necessary gems
46
+ You need to add some gems to your app for Rubyblok to work correctly. Run the following commands:
48
47
 
49
- First, you need to run the install generator, which will create the initializer for you:
50
48
  ```bash
51
- rails g rubyblok:install
49
+ bundle add "storyblok"
50
+ bundle add "hash_dot"
51
+ bundle add "dotenv-rails"
52
52
  ```
53
53
 
54
- Now let's generate and run a migration to create the `pages` table and the `Page` model:
55
- ```bash
56
- rails g rubyblok:migration PAGE
57
-
58
- rails db:migrate
59
- ```
54
+ ### Hello world - Your first Rubyblok page
55
+ Let's get started with Rubyblok by creating your first page in three steps.
56
+ Note that it is important that you have your Storyblok space set up as described above, in the `Storyblok account and new space` section.
60
57
 
61
- Then, generate the webhook controller:
58
+ 1. First, you need to run the install generator, which will create the initializer for you:
62
59
  ```bash
63
- rails g rubyblok:webhook_controller STORYBLOK_WEBHOOK
64
- ```
65
- It also adds this line to your `routes.rb` file:
66
- ```
67
- resources :storyblok_webhook, only: :create
60
+ rails g rubyblok:install
68
61
  ```
69
- The Storyblok webhook is responsible for updating and deleting content in our local database in case of changes of content in Storyblok.
70
62
 
71
- Finally, generate the home controller:
63
+ 2. Now let's generate and run a migration to create the `pages` table and the `Page` model:
72
64
  ```bash
73
- rails g controller home_controller
74
- ```
75
- Add the following code to your home controller:
76
- ```
77
- def index
78
- response.headers['X-FRAME-OPTIONS'] = 'ALLOWALL'
79
- end
80
- ```
81
-
82
- Add this code to your app/views/home/index.html.erb file:
83
- ```
84
- <%= rubyblok_story_tag('home') %>
85
- ```
86
- Configure your `routes.rb` file to call the home controller. For example, adding this line:
87
- ```
88
- root to: 'home#index'
89
- ```
65
+ rails g rubyblok:migration page
90
66
 
91
- Create a `shared/storyblok` directory in the `views` directory, this directory is going to store the partials that render Storyblok components.
92
- You can change the folder settings at the `rubyblok.rb` file as needed:
93
- ```
94
- config.component_path = "shared/storyblok"
67
+ rails db:migrate
95
68
  ```
96
69
 
97
- Inside the `views/shared/storyblok` folder, create a file named `_page.html.erb` with the following code:
98
- ```
99
- <%= rubyblok_blocks_tag(blok.body) %>
70
+ 3. Finally, let's generate your first page:
71
+ ```bash
72
+ rails g rubyblok:hello_world page
100
73
  ```
74
+ This will automatically create a new route, controller, views and styling for your hello world page.
101
75
 
102
- And then create another file for the hero section block `_hero_section.html.erb` (more explanation on that later):
76
+ For this example, go to the `rubyblok.rb` file and turn the caching option off:
103
77
  ```
104
- <section>
105
- <div>
106
- <%= rubyblok_content_tag(blok.headline) %>
107
- <%= rubyblok_content_tag(blok.subheadline) %>
108
- </div>
109
- </section>
78
+ config.cached = false
110
79
  ```
111
80
 
112
- ### Creating your page at Storyblok
113
- 1. Once you're logged in, access your new space in the "My Spaces" section
114
- 2. Go to the "Content" section
115
- 3. Click the CTA "Create new" > Story
116
- 4. Name your story "Home", so it connects to our previous code. The content type is "Page".
117
- 5. Open your new story to start editing.
118
- 6. On the right side, you can add new blocks to your page. Create a new block by clicking the "+ Add Block" button.
119
- 7. This will open the Insert block section, then create the new "hero_section" block by typing its name in the search input.
120
- 8. Click the "Create new hero_section" CTA
121
- 9. Add the "headline" and "subheadline" text fields to the new Hero Section and save.
122
- 10. In your new Hero Section block, add any text you want to it.
123
- 11. Click the Publish button in the right top corner.
81
+ Now you have created your first Hello World page! Start your Rails server, access the '/pages' route and you will be able to see the page.
124
82
 
125
- Now you have your first demo page and block created. Start your rails server and you will be able to see it in your application.
126
-
127
- ### Activate the visual editor
83
+ ### Activate the visual editor
128
84
  Here are the steps to configure the visual editor at Storyblok. This allows you to see a preview of your changes in the Storyblok interface as you edit and save.
129
85
 
130
86
  At Storyblok, select your Space and go to _Settings > Visual Editor_.
@@ -155,6 +111,13 @@ This will start a proxy server.
155
111
 
156
112
  By doing this initial setup, you are able to see your first Storyblok page inside your app and edit its content in the Storyblok admin interface 🎉
157
113
 
114
+ ### Storyblok webhook
115
+ The Storyblok webhook will be responsible for updating and deleting content in the local database in case of changes. [Learn more here.](https://www.storyblok.com/docs/guide/in-depth/webhooks)
116
+
117
+ Generate the webhook controller:
118
+ ```bash
119
+ rails g rubyblok:webhook_controller storyblok_webhook
120
+ ```
158
121
 
159
122
  ## Rubyblok tags
160
123
 
@@ -199,8 +162,7 @@ Use this tag to render more than one component:
199
162
  ```
200
163
 
201
164
  ### Updating content manually at the caching layer
202
-
203
- You can do the following in case you need to update the caching layer with some content that already exists in Storyblok:
165
+ In case you need to update the caching layer with new content added to Storyblok, run the following command:
204
166
  ```
205
167
  # Slug: full_slug of the storyblok story
206
168
  storyblok_story_content = Rubyblok::Services::GetStoryblokStory.call(slug: slug)
@@ -209,7 +171,6 @@ storyblok_story_content = Rubyblok::Services::GetStoryblokStory.call(slug: slug)
209
171
  ```
210
172
 
211
173
  ## How to Run Tests
212
-
213
174
  You can run unit tests for RubyBlok with the following command:
214
175
  ```
215
176
  bundle exec rspec
@@ -223,5 +184,4 @@ Issues should be used to report bugs, request a new feature, or to discuss poten
223
184
  For any inquiries, reach out to us at: info@rubyblok.com
224
185
 
225
186
  ## License
226
-
227
187
  RubyBlok is released under the MIT License.
@@ -0,0 +1,43 @@
1
+ require "rails/generators"
2
+
3
+ module Rubyblok
4
+ module Generators
5
+ class HelloWorldGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path("../templates", __dir__)
7
+
8
+ desc 'Generates a "Hello, world" Rubyblok page.'
9
+
10
+ def generate_hello_world
11
+ add_controller
12
+ add_route
13
+ copy_views
14
+ end
15
+
16
+ private
17
+
18
+ def add_controller
19
+ template("hello_world_generator/controller.rb.erb", "app/controllers/#{plural_file_name}_controller.rb")
20
+ end
21
+
22
+ def add_route
23
+ insert_into_file("config/routes.rb", after: "Rails.application.routes.draw do") do
24
+ "\n get '/#{plural_file_name}' => '#{plural_file_name}#index'\n"
25
+ end
26
+ end
27
+
28
+ def copy_views
29
+ template("hello_world_generator/index.html.erb", "app/views/#{plural_file_name}/index.html.erb")
30
+ template("hello_world_generator/_feature.html.erb", "app/views/#{destination_partial_path}/_feature.html.erb")
31
+ template("hello_world_generator/_page.html.erb", "app/views/#{destination_partial_path}/_page.html.erb")
32
+ template("hello_world_generator/_grid.html.erb", "app/views/#{destination_partial_path}/_grid.html.erb")
33
+ template("hello_world_generator/_teaser.html.erb", "app/views/#{destination_partial_path}/_teaser.html.erb")
34
+
35
+ copy_file("hello_world_generator/styles.css", "app/assets/stylesheets/hello.css")
36
+ end
37
+
38
+ def destination_partial_path
39
+ @destination_partial_path ||= Rubyblok.configuration.component_path
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ <div class="feature">
2
+ <span class="name"><%%= blok.name %></span>
3
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="columns">
2
+ <%%= rubyblok_blocks_tag(blok.columns) %>
3
+ </div>
@@ -0,0 +1 @@
1
+ <%%= rubyblok_blocks_tag(blok.body) %>
@@ -0,0 +1,3 @@
1
+ <div class="teaser">
2
+ <span class="headline"><%%= blok.headline %></span>
3
+ </div>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= class_name.pluralize %>Controller < ApplicationController
4
+ include StoryblokHelper
5
+
6
+ def index
7
+ @slug = "home"
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ <%%= stylesheet_link_tag("hello.css") %>
2
+
3
+ <div class="page">
4
+ <%%= rubyblok_story_tag(@slug) %>
5
+ </div>
@@ -0,0 +1,54 @@
1
+ .page {
2
+ display: flex;
3
+ flex-direction: column;
4
+ align-items: center;
5
+ justify-content: center;
6
+ background: #FFF;
7
+ color: #1B243F;
8
+ width: 100%;
9
+ min-height: 100svh;
10
+ padding: 0;
11
+ margin: 0;
12
+ font-family: sans-serif;
13
+ }
14
+
15
+ .teaser {
16
+ display: flex;
17
+ flex-direction: column;
18
+ align-items: center;
19
+ padding: 2rem 0;
20
+ }
21
+
22
+ .headline {
23
+ font-size: 2rem;
24
+ font-weight: 700;
25
+ margin-bottom: 1rem;
26
+ }
27
+
28
+ .feature {
29
+ display: flex;
30
+ flex-direction: column;
31
+ align-items: center;
32
+ justify-content: center;
33
+ padding: 2rem;
34
+ background: #00B3B0;
35
+ border-radius: 0.5rem;
36
+ }
37
+
38
+ .name {
39
+ color: #FFF;
40
+ font-size: 1.25rem;
41
+ font-weight: 500;
42
+ }
43
+
44
+ .columns {
45
+ display: flex;
46
+ flex-direction: column;
47
+ gap: 1rem;
48
+
49
+ @media (min-width: 768px) {
50
+ display: grid;
51
+ grid-template-columns: repeat(3, minmax(0, 1fr));
52
+ gap: 1rem;
53
+ }
54
+ }
@@ -1,3 +1,5 @@
1
+ require "active_support/concern"
2
+
1
3
  module Rubyblok
2
4
  module Mixins
3
5
  module Model
@@ -1,3 +1,5 @@
1
+ require "active_support/concern"
2
+
1
3
  module Rubyblok
2
4
  module Mixins
3
5
  module Webhook
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubyblok
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/rubyblok.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "storyblok"
4
+ require "redcarpet"
3
5
  require "hash_dot"
4
- require "rails"
5
- require "action_controller"
6
6
 
7
7
  require_relative "rubyblok/helpers/storyblok_helper"
8
8
  require_relative "rubyblok/version"
9
9
  require_relative "rubyblok/configuration"
10
- require_relative "rubyblok/services/get_storyblok_story"
11
10
  require_relative "rubyblok/railtie" if defined?(Rails)
11
+ require_relative "rubyblok/services/get_storyblok_story"
12
12
  require_relative "rubyblok/mixins/model"
13
+ require_relative "rubyblok/mixins/webhook"
13
14
  require_relative "generators/rubyblok/migration_generator"
14
15
  require_relative "generators/rubyblok/install_generator"
15
-
16
- require_relative "rubyblok/mixins/webhook"
17
16
  require_relative "generators/rubyblok/webhook_controller_generator"
17
+ require_relative "generators/rubyblok/hello_world_generator"
18
18
 
19
19
  module Rubyblok
20
20
  def self.configuration
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyblok
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 100 Starlings
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hash_dot
@@ -75,12 +75,21 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".rspec"
77
77
  - ".rubocop.yml"
78
+ - CHANGELOG.md
78
79
  - LICENSE.md
79
80
  - README.md
80
81
  - Rakefile
82
+ - lib/generators/rubyblok/hello_world_generator.rb
81
83
  - lib/generators/rubyblok/install_generator.rb
82
84
  - lib/generators/rubyblok/migration_generator.rb
83
85
  - lib/generators/rubyblok/webhook_controller_generator.rb
86
+ - lib/generators/templates/hello_world_generator/_feature.html.erb
87
+ - lib/generators/templates/hello_world_generator/_grid.html.erb
88
+ - lib/generators/templates/hello_world_generator/_page.html.erb
89
+ - lib/generators/templates/hello_world_generator/_teaser.html.erb
90
+ - lib/generators/templates/hello_world_generator/controller.rb.erb
91
+ - lib/generators/templates/hello_world_generator/index.html.erb
92
+ - lib/generators/templates/hello_world_generator/styles.css
84
93
  - lib/generators/templates/migration_create.rb.erb
85
94
  - lib/generators/templates/migration_update.rb.erb
86
95
  - lib/generators/templates/model.rb.erb
@@ -117,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
126
  - !ruby/object:Gem::Version
118
127
  version: '0'
119
128
  requirements: []
120
- rubygems_version: 3.5.7
129
+ rubygems_version: 3.5.3
121
130
  signing_key:
122
131
  specification_version: 4
123
132
  summary: Simple Storyblok CMS integration for Rails