Skip to content

Commit c73273d

Browse files
committed
refactor: rename the plugin to devto.nvim
We don't support other forem platforms
1 parent d0750f1 commit c73273d

File tree

11 files changed

+68
-68
lines changed

11 files changed

+68
-68
lines changed

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Forem.nvim
1+
# Devto.nvim
22

3-
<p align="center">This plugin integrates Neovim with Forem platforms like [dev.to](https://dev.to)</p>
3+
<p align="center">This plugin integrates Neovim with [dev.to](https://dev.to)</p>
44

55
https://user-images.githubusercontent.com/12272702/175755820-a2b93f4b-fd5c-416b-8b9e-d981335ef75c.mov
66

@@ -35,7 +35,7 @@ You can use the plugin without any dependencies, but if you have any of the foll
3535

3636
```lua
3737
{
38-
"Massolari/forem.nvim",
38+
"Massolari/devto.nvim",
3939
dependencies = {
4040
"nvim-lua/plenary.nvim",
4141
-- Optional
@@ -49,7 +49,7 @@ You can use the plugin without any dependencies, but if you have any of the foll
4949

5050
```lua
5151
use {
52-
"Massolari/forem.nvim",
52+
"Massolari/devto.nvim",
5353
requires = {
5454
"nvim-lua/plenary.nvim",
5555
-- Optional
@@ -68,18 +68,18 @@ First, you need to generate an API key for the DEV platform.
6868

6969
For dev.to, you can do it in [the end of the extension's page](https://dev.to/settings/extensions)
7070

71-
With your API key, you just need to set it into the `FOREM_API_KEY` environment variable.
71+
With your API key, you just need to set it into the `DEVTO_API_KEY` environment variable.
7272

7373
## Usage
7474

75-
The plugin has the following commands and functions available in `forem-nvim` module:
75+
The plugin has the following commands and functions available in `devto-nvim` module:
7676

7777
| function | command | description |
7878
| --------------- | -------------------- | -------------------------------------------------------------------------------------------- |
79-
| `feed()` | `:Forem feed` | Shows fresh articles from the feed, then you can read it in Neovim or open it in the browser |
80-
| `my_articles()` | `:Forem my_articles` | Shows all your articles, then you can pick one to edit |
81-
| `new_article()` | `:Forem new_article` | Asks for a title, then creates an article with the given title and open it to edit |
82-
| `open_by_url()` | `:Forem open_by_url` | Asks for a URL, then opens the article |
79+
| `feed()` | `:Devto feed` | Shows fresh articles from the feed, then you can read it in Neovim or open it in the browser |
80+
| `my_articles()` | `:Devto my_articles` | Shows all your articles, then you can pick one to edit |
81+
| `new_article()` | `:Devto new_article` | Asks for a title, then creates an article with the given title and open it to edit |
82+
| `open_by_url()` | `:Devto open_by_url` | Asks for a URL, then opens the article |
8383

8484
After you save the buffer it'll automatically be saved in the cloud.
8585

lua/forem-nvim/api.lua lua/devto-nvim/api.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
local M = {}
2-
local notify = require("forem-nvim.notify")
3-
local article = require("forem-nvim.article")
2+
local notify = require("devto-nvim.notify")
3+
local article = require("devto-nvim.article")
44

55
function M.key()
6-
return vim.env.FOREM_API_KEY
6+
return vim.env.devto_API_KEY
77
end
88

99
local BASE_URL = "https://dev.to/api"
@@ -102,7 +102,7 @@ local function request(method, endpoint, options)
102102
headers = {
103103
"api-key: " .. M.key(),
104104
"Content-Type: application/json",
105-
"Accept: application/vnd.forem.api-v1+json"
105+
"Accept: application/vnd.devto.api-v1+json"
106106
}
107107
},
108108
options
File renamed without changes.

lua/forem-nvim/buffer.lua lua/devto-nvim/buffer.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
2-
local Article = require("forem-nvim.article")
3-
local util = require("forem-nvim.util")
2+
local Article = require("devto-nvim.article")
3+
local util = require("devto-nvim.util")
44
local set_locals = util.set_locals
55

66
M.set_basic_options = function()
@@ -33,7 +33,7 @@ M.get_content = function()
3333
end
3434

3535
M.open_my_article = function(article)
36-
vim.cmd(":edit forem://my-article/" .. tostring(article.id))
36+
vim.cmd(":edit devto://my-article/" .. tostring(article.id))
3737
local buffer = vim.api.nvim_get_current_buf()
3838
M.write(
3939
buffer,
@@ -44,7 +44,7 @@ M.open_my_article = function(article)
4444
end
4545

4646
M.load_article = function(article)
47-
vim.cmd(":edit forem://article/" .. article.title)
47+
vim.cmd(":edit devto://article/" .. article.title)
4848
set_locals({ linebreak = true, textwidth = 80 })
4949
local buffer = vim.api.nvim_get_current_buf()
5050
local body = Article.get_body_lines(article)

lua/forem-nvim/feed.lua lua/devto-nvim/feed.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
local M = {}
2-
local api = require("forem-nvim.api")
3-
local buffer = require("forem-nvim.buffer")
4-
local notify = require("forem-nvim.notify")
5-
local util = require("forem-nvim.util")
2+
local api = require("devto-nvim.api")
3+
local buffer = require("devto-nvim.buffer")
4+
local notify = require("devto-nvim.notify")
5+
local util = require("devto-nvim.util")
66
local set_locals = util.set_locals
77

88
function M.open()
9-
return vim.cmd("edit forem://articles/feed")
9+
return vim.cmd("edit devto://articles/feed")
1010
end
1111

1212
local function set_basic_options()
@@ -62,7 +62,7 @@ function M.open_article(location)
6262
return
6363
end
6464

65-
local article_data = _G.forem_feed_articles and _G.forem_feed_articles[title]
65+
local article_data = _G.devto_feed_articles and _G.devto_feed_articles[title]
6666
if not article_data then
6767
notify.error("Could not find article data. Please reload the feed.")
6868
return
@@ -91,9 +91,9 @@ local function set_key_maps()
9191
end
9292

9393
local function populate_global_feed_articles(articles)
94-
_G.forem_feed_articles = {}
94+
_G.devto_feed_articles = {}
9595
for _, article in ipairs(articles) do
96-
_G.forem_feed_articles[article.title] = { id = article.id, url = article.url }
96+
_G.devto_feed_articles[article.title] = { id = article.id, url = article.url }
9797
end
9898
end
9999

lua/forem-nvim/init.lua lua/devto-nvim/init.lua

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
local M = {}
2-
local api = require("forem-nvim.api")
3-
local buffer = require("forem-nvim.buffer")
4-
local feed = require("forem-nvim.feed")
5-
local notify = require("forem-nvim.notify")
6-
local picker = require("forem-nvim.picker")
2+
local api = require("devto-nvim.api")
3+
local buffer = require("devto-nvim.buffer")
4+
local feed = require("devto-nvim.feed")
5+
local notify = require("devto-nvim.notify")
6+
local picker = require("devto-nvim.picker")
77

8-
local NO_API_KEY_ERROR = "forem.nvim: FOREM_API_KEY environment variable is missing"
8+
local NO_API_KEY_ERROR = "devto.nvim: devto_API_KEY environment variable is missing"
99

1010
local function check_api_key(callback)
1111
if api.key() then
@@ -26,7 +26,7 @@ local function save_article()
2626
local id = tonumber(vim.fn.expand("%:t"))
2727

2828
if not id then
29-
notify.error("forem.nvim: Could not find article id")
29+
notify.error("devto.nvim: Could not find article id")
3030
return
3131
end
3232

@@ -79,17 +79,17 @@ local function open_by_url()
7979
api.get_article_by_path(path, buffer.load_article)
8080
end
8181

82-
local forem_au_group = vim.api.nvim_create_augroup("forem_autocmds", {})
82+
local devto_au_group = vim.api.nvim_create_augroup("devto_autocmds", {})
8383

8484
vim.api.nvim_create_autocmd("BufWriteCmd",
85-
{ group = forem_au_group, pattern = "forem://my-article/*", callback = save_article })
85+
{ group = devto_au_group, pattern = "devto://my-article/*", callback = save_article })
8686
vim.api.nvim_create_autocmd("BufEnter",
87-
{ group = forem_au_group, pattern = "forem://articles/feed", callback = feed.load })
87+
{ group = devto_au_group, pattern = "devto://articles/feed", callback = feed.load })
8888
vim.api.nvim_create_autocmd(
8989
"CursorMoved",
9090
{
91-
group = forem_au_group,
92-
pattern = "forem://*/floatmenu",
91+
group = devto_au_group,
92+
pattern = "devto://*/floatmenu",
9393
callback = function()
9494
local bufnum, line, column, off = unpack(vim.fn.getpos("."))
9595
if column <= 1 then
@@ -102,8 +102,8 @@ vim.api.nvim_create_autocmd(
102102
vim.api.nvim_create_autocmd(
103103
"BufEnter",
104104
{
105-
group = forem_au_group,
106-
pattern = "forem://*/floatmenu",
105+
group = devto_au_group,
106+
pattern = "devto://*/floatmenu",
107107
callback = function()
108108
vim.keymap.set(
109109
"n",

lua/forem-nvim/notify.lua lua/devto-nvim/notify.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
22
local function notify(message, level)
3-
vim.notify(message, vim.log.levels[level], { title = "Forem.nvim" })
3+
vim.notify(message, vim.log.levels[level], { title = "Devto.nvim" })
44
end
55
function M.error(message) return notify(message, "ERROR") end
66

lua/forem-nvim/picker.lua lua/devto-nvim/picker.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
2-
local buffer = require("forem-nvim.buffer")
3-
local Article = require("forem-nvim.article")
2+
local buffer = require("devto-nvim.buffer")
3+
local Article = require("devto-nvim.article")
44

55
local function my_articles_telescope_picker(articles)
66
local telescope_config = require("telescope.config")

lua/forem-nvim/util.lua lua/devto-nvim/util.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function M.open_float_menu(content, options)
6262
true,
6363
content
6464
)
65-
vim.api.nvim_buf_set_name(bufnr, "forem://feed/floatmenu")
65+
vim.api.nvim_buf_set_name(bufnr, "devto://feed/floatmenu")
6666
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
6767
vim.api.nvim_set_option_value("bufhidden", "delete", { buf = bufnr })
6868
vim.api.nvim_set_option_value("cursorline", true, { win = window })

plugin/forem-nvim.lua plugin/devto-nvim.lua

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
2-
local forem = require("forem-nvim")
3-
local notify = require("forem-nvim.notify")
2+
local devto = require("devto-nvim")
3+
local notify = require("devto-nvim.notify")
44

55
local commands = {
66
feed = "feed",
@@ -10,18 +10,18 @@ local commands = {
1010
}
1111

1212
vim.api.nvim_create_user_command(
13-
"Forem",
13+
"devto",
1414
function(data)
1515
local args = data.args
1616

1717
if args == commands.feed then
18-
return forem.feed()
18+
return devto.feed()
1919
elseif args == commands.my_articles then
20-
return forem.my_articles()
20+
return devto.my_articles()
2121
elseif args == commands.new_article then
22-
return forem.new_article()
22+
return devto.new_article()
2323
elseif args == commands.open_url then
24-
return forem.open_url()
24+
return devto.open_url()
2525
else
2626
notify.error("Unknown command: " .. args)
2727
end

tests/forem-nvim/setup_spec.lua tests/devto-nvim/setup_spec.lua

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ local M = {}
22
local stub = require("luassert.stub")
33
local spy = require("luassert.spy")
44
local match = require("luassert.match")
5-
local article = require("forem-nvim.article")
5+
local article = require("devto-nvim.article")
66
local busted = require("plenary.busted")
77
local describe = busted.describe
88
local before_each = busted.before_each
99
local after_each = busted.after_each
1010
local it = busted.it
1111

1212
local function mock_internal(module)
13-
_G.package.loaded["forem-nvim"] = nil
13+
_G.package.loaded["devto-nvim"] = nil
1414
_G.package.loaded[module] = nil
1515
local mocked = require(module)
1616
return mocked
1717
end
1818

1919
describe(
20-
"Forem.nvim",
20+
"devto.nvim",
2121
function()
22-
local forem_nvim
22+
local devto_nvim
2323
local snapshot
2424

2525
before_each(function()
26-
vim.env.FOREM_API_KEY = "foo"
27-
_G.package.loaded["forem-nvim"] = nil
28-
forem_nvim = require("forem-nvim")
26+
vim.env.devto_API_KEY = "foo"
27+
_G.package.loaded["devto-nvim"] = nil
28+
devto_nvim = require("devto-nvim")
2929
snapshot = assert:snapshot()
3030
end)
3131

@@ -36,21 +36,21 @@ describe(
3636
it(
3737
"should show a notification when no api key is set",
3838
function()
39-
vim.env.FOREM_API_KEY = nil
39+
vim.env.devto_API_KEY = nil
4040
stub.new(vim, "notify")
41-
forem_nvim.my_articles()
41+
devto_nvim.my_articles()
4242
assert.stub(vim.notify).was.called()
4343
end
4444
)
4545

4646
it(
4747
"should call the api to get the articles",
4848
function()
49-
local mocked_api = mock_internal("forem-nvim.api")
49+
local mocked_api = mock_internal("devto-nvim.api")
5050
mocked_api.my_articles = spy.new(function()
5151
end)
52-
local forem_nvim_mocked = require("forem-nvim")
53-
forem_nvim_mocked.my_articles()
52+
local devto_nvim_mocked = require("devto-nvim")
53+
devto_nvim_mocked.my_articles()
5454
assert.spy(mocked_api.my_articles).was.called()
5555
end
5656
)
@@ -60,21 +60,21 @@ describe(
6060
function()
6161
local input = stub.new(vim.fn, "input")
6262
input.returns("Title")
63-
local api = mock_internal("forem-nvim.api")
63+
local api = mock_internal("devto-nvim.api")
6464
local api_new_article = stub.new(api, "new_article")
6565
local new_article = {
6666
id = 1,
6767
body_markdown = article.get_template("Title")
6868
}
6969
api_new_article.returns({ status = 201, body = new_article })
70-
local buffer = mock_internal("forem-nvim.buffer")
70+
local buffer = mock_internal("devto-nvim.buffer")
7171
local buffer_open_my_article = spy.on(buffer, "open_my_article")
72-
local forem_nvim_mocked = require("forem-nvim")
73-
forem_nvim_mocked.new_article()
72+
local devto_nvim_mocked = require("devto-nvim")
73+
devto_nvim_mocked.new_article()
7474
assert.stub(api_new_article).was.called_with("Title")
7575
assert.spy(buffer_open_my_article).was_called_with(match.is_same(new_article))
7676
assert.are.same(
77-
"forem://my-article/" .. tostring(new_article.id),
77+
"devto://my-article/" .. tostring(new_article.id),
7878
vim.api.nvim_buf_get_name(0)
7979
)
8080
local buffer_content = vim.api.nvim_buf_get_lines(0, 0, -1, true)

0 commit comments

Comments
 (0)