Skip to content

Commit

Permalink
toggleable language option
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyshear committed Nov 21, 2024
1 parent cec2ee6 commit 0646d2e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
17 changes: 12 additions & 5 deletions lua/drash/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ local drash_parsha = require('drash.parsha')
local telescope_drash = require('telescope._extensions.drash')
local M = {}

M.setup = function(spec, opts)
_ = spec
_ = opts
M.setup = function(opts)
opts = opts or {
text_language = 'english',
}

telescope.load_extension('drash')
vim.api.nvim_create_user_command('SearchSefaria', function(opt)
telescope_drash.exports.search_sefaria({ prompt = opt.args, text_language = opts.text_language })
end, { nargs = '?' })
vim.api.nvim_create_user_command('Parsha', function()
local parsha_info = drash_parsha.parsha()
local parsha_info = drash_parsha.parsha(opts)
if parsha_info == nil then
return nil
end
Expand All @@ -19,7 +23,10 @@ M.setup = function(spec, opts)
vim.api.nvim_set_option_value('modifiable', false, { buf = bufnr })
vim.api.nvim_win_set_buf(0, bufnr)
vim.api.nvim_buf_create_user_command(bufnr, 'Commentaries', function()
telescope_drash.exports.browse_commentaries({ commentaries = parsha_info.commentaries })
telescope_drash.exports.browse_commentaries({
commentaries = parsha_info.commentaries,
text_language = opts.text_language,
})
end, {})
end, {})
end
Expand Down
4 changes: 2 additions & 2 deletions lua/drash/parsha.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local sefaria = require('drash.sefaria')
local M = {}

M.parsha = function()
M.parsha = function(opts)
local calendar = sefaria.get_calendar()
if calendar == nil then
return nil
Expand All @@ -15,7 +15,7 @@ M.parsha = function()
end
end

local parsha = sefaria.get_text(parsha_ref)
local parsha = sefaria.get_text(opts.text_language, parsha_ref)
if parsha == nil then
return nil
end
Expand Down
4 changes: 2 additions & 2 deletions lua/drash/sefaria.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ M.post_find_refs = function(title, body)
return data
end

M.get_text = function(ref)
M.get_text = function(text_language, ref)
ref = drash_utils.url_encode(ref)
local url = 'https://www.sefaria.org/api/v3/texts/' .. ref

local response = plenary_curl.get(url, {
query = { version = 'english', return_format = 'text_only' },
query = { version = text_language, return_format = 'text_only' },
})

if response.status ~= 200 then
Expand Down
23 changes: 12 additions & 11 deletions lua/telescope/_extensions/drash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local conf = require('telescope.config').values
local M = {}

M.search_sefaria = function(opts)
opts = opts or { prompt = '' }
opts = opts or { prompt = '', opts.text_language }

local searcher = function(prompt)
if not prompt or prompt == '' then
Expand Down Expand Up @@ -47,6 +47,7 @@ M.search_sefaria = function(opts)
end

local response = require('drash.sefaria').get_text(
opts.text_language,
selected.value._source.ref or selected.value.source.ref
)
local text = {}
Expand All @@ -67,8 +68,10 @@ M.search_sefaria = function(opts)
end,
previewer = previewers.new_buffer_previewer({
define_preview = function(self, entry)
local response =
require('drash.sefaria').get_text(entry.value._source.ref or entry.value.source.ref)
local response = require('drash.sefaria').get_text(
opts.text_language,
entry.value._source.ref or entry.value.source.ref
)
local text = {}
if response == nil then
text = { 'Error fetching text' }
Expand All @@ -85,7 +88,10 @@ M.search_sefaria = function(opts)
end

M.browse_commentaries = function(opts)
opts = opts or { commentaries = {} }
opts = opts or {
commentaries = {},
text_language = 'english',
}

pickers
.new(opts, {
Expand All @@ -101,7 +107,7 @@ M.browse_commentaries = function(opts)
return
end

local response = require('drash.sefaria').get_text(selected.value)
local response = require('drash.sefaria').get_text(opts.text_language, selected.value)
local text = {}
if response == nil then
text = { 'Error fetching text' }
Expand All @@ -126,7 +132,7 @@ M.browse_commentaries = function(opts)
end,
previewer = previewers.new_buffer_previewer({
define_preview = function(self, entry)
local response = require('drash.sefaria').get_text(entry.value)
local response = require('drash.sefaria').get_text(opts.text_language, entry.value)
local text = {}
if response == nil then
text = { 'Error fetching text' }
Expand All @@ -149,11 +155,6 @@ M.browse_commentaries = function(opts)
end

return telescope.register_extension({
setup = function()
vim.api.nvim_create_user_command('SearchSefaria', function(opts)
M.search_sefaria({ prompt = opts.args })
end, { nargs = '?' })
end,
exports = {
search_sefaria = M.search_sefaria,
browse_commentaries = M.browse_commentaries,
Expand Down

0 comments on commit 0646d2e

Please sign in to comment.