Skip to content

Commit

Permalink
feat(files): Add get_directive method to file
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Mar 31, 2024
1 parent c79e06c commit 96a30ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/orgmode/files/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,13 @@ function OrgFile:get_links()
return links
end

memoize('get_directive')
---@param directive_name string
---@return string | nil
function OrgFile:get_directive(directive_name)
return self:_get_directive(directive_name)
end

---@private
---@return string | nil
function OrgFile:_get_directive(directive_name)
Expand Down
13 changes: 13 additions & 0 deletions tests/plenary/files/file_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -815,5 +815,18 @@ describe('OrgFile', function()
})
assert.are.same('112233', file:get_property('custom_id'))
end)

it('should get directive', function()
local file = load_file_sync({
':PROPERTIES:',
':ID: 443355',
':CUSTOM_ID: 112233',
':END:',
'#+somedirective: somevalue',
'#+title: test',
'* TODO Headline 1',
})
assert.are.same('somevalue', file:get_directive('somedirective'))
end)
end)
end)

0 comments on commit 96a30ff

Please sign in to comment.