tinycms 0.1.1 → 0.1.3

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: fa0c4fb70348684b50ca97c4fda49dc8e09952033b95bcbfbeee6b4dfd840960
4
- data.tar.gz: e98b821a13fe0ee239fd5c0850eed29ed8b16e4076c0f610aa0939556ffa7875
3
+ metadata.gz: 8b26637277ab8f25e0a52fb3a922f75e70c26f12c76f8eeb65e7da52e09626be
4
+ data.tar.gz: f6d26c1525168d41de67c5175f74018b44a6de8890382b1f523af1bfae539e40
5
5
  SHA512:
6
- metadata.gz: a01e12267ac40b99680234a8354258682ff1bbf208b9bb7d68b4e68d85c646ef1b5a5f4bbcb2027f0368e4cfe5791f7f4402f67109a835f41ac6c0055d7ab372
7
- data.tar.gz: a03f502dc00ab0157ceb9d7f23a09b1e13d4da4f55f6ca50514d3a0e289679d5e8294f18af31b9229df6644d4785003b9328c754a7ef10a75575116169c959d1
6
+ metadata.gz: fbecea65017edf08c97cdc8dca717c38f798dcad8da08653de8bec9d526c095cec21992edcc2e5bb18764dbcb722d82ddacb7313199734d1d60f2d78ec0e06e7
7
+ data.tar.gz: ae10dc67c6c6a015bf98d0145e9be5bb5b03013632d8ac2bd0a01d734421dd5455d9db6778f143ef53b0dedad28d9fc028049dc91268932343ec97de3b07a74f
data/README.md CHANGED
@@ -1,24 +1,127 @@
1
1
  # Tinycms
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
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 UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
11
+ $ bundle add tinycms
12
+
13
+ Create an initializer in `config/initializers/tinycms.rb`. And configure the initializer as:
14
14
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
15
+ ```ruby
16
+ Tinycms.configure do |config|
17
+ config.api_key = `YOUR-API-KEY`
18
+ end
19
+ ```
16
20
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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
- TODO: Write usage instructions here
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/[USERNAME]/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/[USERNAME]/tinycms/blob/master/CODE_OF_CONDUCT.md).
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
 
@@ -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
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Tinycms
4
4
  class BaseApi
5
- def client
6
- @client ||= Tinycms::Client.new.client
5
+ def self.client
6
+ Tinycms::Client.new.client
7
7
  end
8
8
  end
9
9
  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
@@ -5,7 +5,7 @@ require "retriable"
5
5
  module Tinycms
6
6
  module Blogs
7
7
  class Api < BaseApi
8
- def get_all
8
+ def self.get_all
9
9
  Retriable.retriable do
10
10
  response = client.get("/api/blogs")
11
11
  blogs = response.body
@@ -15,7 +15,7 @@ module Tinycms
15
15
  end
16
16
  end
17
17
 
18
- def get(blog_id)
18
+ def self.get(blog_id)
19
19
  Retriable.retriable do
20
20
  response = client.get("/api/blogs/#{blog_id}")
21
21
  Tinycms::Blogs::Mapper.map(response.body)
@@ -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
@@ -5,7 +5,7 @@ require "retriable"
5
5
  module Tinycms
6
6
  module Posts
7
7
  class Api < BaseApi
8
- def get(post_id)
8
+ def self.get(post_id)
9
9
  Retriable.retriable do
10
10
  response = client.get("/api/posts/#{post_id}")
11
11
  Tinycms::Posts::Mapper.map(response.body)
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tinycms
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
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.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-04 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable