tinycms 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +112 -9
- data/lib/tinycms/author.rb +4 -2
- data/lib/tinycms/authors/mapper.rb +3 -1
- data/lib/tinycms/blog.rb +4 -2
- data/lib/tinycms/blogs/mapper.rb +3 -1
- data/lib/tinycms/post.rb +4 -2
- data/lib/tinycms/posts/mapper.rb +3 -1
- data/lib/tinycms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b26637277ab8f25e0a52fb3a922f75e70c26f12c76f8eeb65e7da52e09626be
|
4
|
+
data.tar.gz: f6d26c1525168d41de67c5175f74018b44a6de8890382b1f523af1bfae539e40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbecea65017edf08c97cdc8dca717c38f798dcad8da08653de8bec9d526c095cec21992edcc2e5bb18764dbcb722d82ddacb7313199734d1d60f2d78ec0e06e7
|
7
|
+
data.tar.gz: ae10dc67c6c6a015bf98d0145e9be5bb5b03013632d8ac2bd0a01d734421dd5455d9db6778f143ef53b0dedad28d9fc028049dc91268932343ec97de3b07a74f
|
data/README.md
CHANGED
@@ -1,24 +1,127 @@
|
|
1
1
|
# Tinycms
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tinycms`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
This gem is used to integrate your Rails app with the Tinycms headless CMS. Add the gem to your Rails app, set the api_key in the initializer, and you're ready to go.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
This gem is meant to be used with Rails apps.
|
10
8
|
|
11
9
|
Install the gem and add to the application's Gemfile by executing:
|
12
10
|
|
13
|
-
$ bundle add
|
11
|
+
$ bundle add tinycms
|
12
|
+
|
13
|
+
Create an initializer in `config/initializers/tinycms.rb`. And configure the initializer as:
|
14
14
|
|
15
|
-
|
15
|
+
```ruby
|
16
|
+
Tinycms.configure do |config|
|
17
|
+
config.api_key = `YOUR-API-KEY`
|
18
|
+
end
|
19
|
+
```
|
16
20
|
|
17
|
-
|
21
|
+
To get the api key, sign up for [TinyCMS](https://www.tinycms.app) and grab the api key in the settings page.
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
25
|
+
The gem is simple, meant to pull down blogs and posts.
|
26
|
+
|
27
|
+
### Blogs
|
28
|
+
```ruby
|
29
|
+
# get all blogs
|
30
|
+
Tinycms::Blogs::Api.get_all
|
31
|
+
|
32
|
+
# get blog via blog_id or slug
|
33
|
+
Tinycms::Blogs::Api.get(<blog_id>)
|
34
|
+
# or
|
35
|
+
Tinycms::Blogs::Api.api.get(<slug>)
|
36
|
+
```
|
37
|
+
|
38
|
+
The blogs api will return instance(s) of blog(s) with a list of posts. You can use the post ids that you get in this endpoint to make requests to the posts endpoint.
|
39
|
+
|
40
|
+
### Posts
|
41
|
+
```ruby
|
42
|
+
# get post via post_id or slug
|
43
|
+
Tinycms::Posts::Api.get(<post_id>)
|
44
|
+
Tinycms::Posts::Api.get(<slug>)
|
45
|
+
```
|
46
|
+
|
47
|
+
The posts api will return an instance of a post with the author information.
|
48
|
+
|
49
|
+
### Rendering Blogs and Posts
|
50
|
+
|
51
|
+
Add to your routes file `config/routes.rb` the following routes. Customize the routes to your needs/preferences.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Rails.application.routes.draw do
|
55
|
+
get "blogs", to: "blogs#index"
|
56
|
+
get "blogs/:id", to: "blogs#show"
|
57
|
+
|
58
|
+
get "posts/:id", to: "posts#show"
|
59
|
+
|
60
|
+
# OR...
|
61
|
+
resources :blogs, only: [:index, :show]
|
62
|
+
resources :posts, only: :show
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
Rendering blogs and posts
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
class BlogsController < ApplicationController
|
70
|
+
def index
|
71
|
+
@blogs = Tinycms::Blogs::Api.get_all
|
72
|
+
end
|
73
|
+
|
74
|
+
def show
|
75
|
+
@blog = Tinycms::Blogs::Api.get(params[:id])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
```html
|
81
|
+
# index.html.erb
|
82
|
+
# link via via blog id
|
83
|
+
<ul>
|
84
|
+
<% @blogs.each do |blog| %>
|
85
|
+
<li><%= link_to blog.name, blog_path(id: blog.id) %></li>
|
86
|
+
<% end %>
|
87
|
+
</ul>
|
88
|
+
|
89
|
+
# link via via blog slug
|
90
|
+
<ul>
|
91
|
+
<% @blogs.each do |blog| %>
|
92
|
+
<li><%= link_to blog.name, blog_path(id: blog.slug) %></li>
|
93
|
+
<% end %>
|
94
|
+
</ul>
|
95
|
+
|
96
|
+
# show.html.erb
|
97
|
+
# link via post id
|
98
|
+
<ul>
|
99
|
+
<% @blog.posts.each do |post| %>
|
100
|
+
<li><%= link_to post.title, post_path(id: post.id) %></li>
|
101
|
+
<% end %>
|
102
|
+
</ul>
|
103
|
+
|
104
|
+
# link via post slug
|
105
|
+
<ul>
|
106
|
+
<% @blog.posts.each do |post| %>
|
107
|
+
<li><%= link_to post.title, post_path(id: post.slug) %></li>
|
108
|
+
<% end %>
|
109
|
+
</ul>
|
110
|
+
```
|
111
|
+
|
112
|
+
Rendering a post
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
class PostsController < ApplicationController
|
116
|
+
def show
|
117
|
+
@post = Tinycms::Posts::Api.get(params[:id])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
```html
|
123
|
+
<%= @post.content.html_safe %>
|
124
|
+
```
|
22
125
|
|
23
126
|
## Development
|
24
127
|
|
@@ -28,7 +131,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
28
131
|
|
29
132
|
## Contributing
|
30
133
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
134
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/typefastco/tinycms. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/typefastco/tinycms/blob/master/CODE_OF_CONDUCT.md).
|
32
135
|
|
33
136
|
## License
|
34
137
|
|
data/lib/tinycms/author.rb
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
module Tinycms
|
4
4
|
class Author
|
5
|
-
def initialize(id:, email:, first_name:, last_name:)
|
5
|
+
def initialize(id:, email:, first_name:, last_name:, created_at:, updated_at:)
|
6
6
|
@id = id
|
7
7
|
@email = email
|
8
8
|
@first_name = first_name
|
9
9
|
@last_name = last_name
|
10
|
+
@created_at = created_at
|
11
|
+
@updated_at = updated_at
|
10
12
|
end
|
11
13
|
|
12
|
-
attr_reader :id, :email, :first_name, :last_name
|
14
|
+
attr_reader :id, :email, :first_name, :last_name, :created_at, :updated_at
|
13
15
|
end
|
14
16
|
end
|
@@ -8,7 +8,9 @@ module Tinycms
|
|
8
8
|
id: response_body["id"],
|
9
9
|
email: response_body["email"],
|
10
10
|
first_name: response_body["first_name"],
|
11
|
-
last_name: response_body["last_name"]
|
11
|
+
last_name: response_body["last_name"],
|
12
|
+
created_at: response_body["created_at"],
|
13
|
+
updated_at: response_body["updated_at"]
|
12
14
|
)
|
13
15
|
end
|
14
16
|
end
|
data/lib/tinycms/blog.rb
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
module Tinycms
|
4
4
|
class Blog
|
5
|
-
def initialize(id:, name:, description:, posts: [])
|
5
|
+
def initialize(id:, name:, description:, posts: [], created_at:, updated_at:)
|
6
6
|
@id = id
|
7
7
|
@name = name
|
8
8
|
@description = description
|
9
9
|
@posts = posts
|
10
|
+
@created_at = created_at
|
11
|
+
@updated_at = updated_at
|
10
12
|
end
|
11
13
|
|
12
|
-
attr_reader :id, :name, :description, :posts
|
14
|
+
attr_reader :id, :name, :description, :posts, :created_at, :updated_at
|
13
15
|
end
|
14
16
|
end
|
data/lib/tinycms/blogs/mapper.rb
CHANGED
@@ -11,7 +11,9 @@ module Tinycms
|
|
11
11
|
id: response_body["id"],
|
12
12
|
name: response_body["name"],
|
13
13
|
description: response_body["description"],
|
14
|
-
posts: posts
|
14
|
+
posts: posts,
|
15
|
+
created_at: response_body["created_at"],
|
16
|
+
updated_at: response_body["updated_at"]
|
15
17
|
)
|
16
18
|
end
|
17
19
|
end
|
data/lib/tinycms/post.rb
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
module Tinycms
|
4
4
|
class Post
|
5
|
-
def initialize(id:, title:, author:, content:)
|
5
|
+
def initialize(id:, title:, author:, content:, created_at:, updated_at:)
|
6
6
|
@id = id
|
7
7
|
@title = title
|
8
8
|
@author = author
|
9
9
|
@content = content
|
10
|
+
@created_at = created_at
|
11
|
+
@updated_at = updated_at
|
10
12
|
end
|
11
13
|
|
12
|
-
attr_reader :id, :title, :author, :content
|
14
|
+
attr_reader :id, :title, :author, :content, :created_at, :updated_at
|
13
15
|
end
|
14
16
|
end
|
data/lib/tinycms/posts/mapper.rb
CHANGED
@@ -8,7 +8,9 @@ module Tinycms
|
|
8
8
|
id: response_body["id"],
|
9
9
|
title: response_body["title"],
|
10
10
|
author: ::Tinycms::Authors::Mapper.map(response_body["author"]),
|
11
|
-
content: response_body["content"]
|
11
|
+
content: response_body["content"],
|
12
|
+
created_at: response_body["created_at"],
|
13
|
+
updated_at: response_body["updated_at"]
|
12
14
|
)
|
13
15
|
end
|
14
16
|
end
|
data/lib/tinycms/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinycms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Jeon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|