├── VimFlavor.lock ├── VimFlavor ├── .gitignore ├── Guardfile ├── Gemfile ├── addon-info.json ├── Gemfile.lock ├── Rakefile ├── autoload └── jekyll.vim ├── README.md ├── doc └── jekyll.txt └── plugin └── jekyll.vim /VimFlavor.lock: -------------------------------------------------------------------------------- 1 | kana/vim-vspec (1.4.0) 2 | -------------------------------------------------------------------------------- /VimFlavor: -------------------------------------------------------------------------------- 1 | flavor 'kana/vim-vspec', '~> 1.4' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vim-flavor 2 | 3 | # Packaged plug-in dir 4 | pkg/ 5 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | guard 'rake', :task => 'test' do 2 | watch(%r{^autoload/.*\.vim$}) 3 | watch(%r{^t/.*\.vim$}) 4 | end 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | group :development do 4 | gem 'rake' 5 | end 6 | 7 | group :test do 8 | gem 'vim-flavor', '~> 1.1' 9 | gem 'rake' 10 | end 11 | -------------------------------------------------------------------------------- /addon-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jekyll", 3 | "version": "0.1.0", 4 | "author": "Noah Frederick", 5 | "description": "Vim extensions for Jekyll 2 sites", 6 | "homepage": "https://github.com/noahfrederick/vim-jekyll" 7 | } 8 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | blankslate (2.1.2.4) 5 | parslet (1.5.0) 6 | blankslate (~> 2.0) 7 | rake (12.3.3) 8 | thor (0.18.1) 9 | vim-flavor (1.1.2) 10 | parslet (~> 1.0) 11 | thor (~> 0.14) 12 | 13 | PLATFORMS 14 | ruby 15 | 16 | DEPENDENCIES 17 | rake 18 | vim-flavor (~> 1.1) 19 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | 3 | require 'rake/packagetask' 4 | require 'json' 5 | 6 | plugin = JSON.load(File.new('addon-info.json')) 7 | 8 | desc 'Target for CI server' 9 | task :ci => [:dump, :test] 10 | 11 | desc 'Dump Vim\'s version info' 12 | task :dump do 13 | sh 'vim --version' 14 | end 15 | 16 | desc 'Run tests with vspec' 17 | task :test do 18 | sh 'bundle exec vim-flavor test || echo "Exit status: $?"' 19 | end 20 | 21 | desc 'Rebuild the documentation with vimdoc' 22 | task :doc do 23 | sh 'vimdoc ./' 24 | end 25 | 26 | Rake::PackageTask.new(plugin['name']) do |p| 27 | p.version = plugin['version'] 28 | p.need_zip = true 29 | p.package_files.include(['plugin/*.vim', 'autoload/*.vim', 'doc/*.txt']) 30 | end 31 | -------------------------------------------------------------------------------- /autoload/jekyll.vim: -------------------------------------------------------------------------------- 1 | " autoload/jekyll.vim - Jekyll autoloads 2 | " Maintainer: Noah Frederick 3 | 4 | "" 5 | " @public 6 | " Get the version number of @plugin(stylized) (e.g., '1.0.0') 7 | function! jekyll#version() 8 | return '0.1.0' 9 | endfunction 10 | 11 | "" 12 | " @private 13 | " Publish a draft post by moving it into _posts/ and prepending the current 14 | " date to the filename. 15 | " 16 | " This makes assumptions about the structure of your site, namely that 17 | " _drafts/ and _posts/ are at the root of your project and that you do not use 18 | " subdirectories in either. 19 | function! jekyll#publish() 20 | let src = expand('%:p') 21 | let slug = strftime('%Y-%m-%d') . '-' . fnamemodify(src, ':t') 22 | let dst = fnamemodify(src, ':h:h') . '/_posts/' . slug 23 | 24 | if !isdirectory(fnamemodify(dst, ':h')) 25 | call mkdir(fnamemodify(dst, ':h'), 'p') 26 | endif 27 | 28 | if rename(src, dst) 29 | echoerr 'Failed to rename "' . src . '" to "' . dst . '"' 30 | else 31 | setlocal modified 32 | execute 'keepalt saveas! ' . fnameescape(dst) 33 | 34 | if src !=# expand('%:p') 35 | execute 'bwipe ' . fnameescape(src) 36 | endif 37 | endif 38 | endfunction 39 | 40 | "" 41 | " Set up buffer-local commands for draft buffers 42 | function! s:draft_buffer_setup() 43 | "" 44 | " Publish the current draft post (only available in draft buffers). 45 | " 46 | " This command moves the current buffer's file from the _drafts/ directory 47 | " to the _posts/ directory and prepends the current date as the published 48 | " date. 49 | command! -buffer -bar -nargs=0 Publish call jekyll#publish() 50 | endfunction 51 | 52 | "" 53 | " @private 54 | " Set up Jekyll buffers 55 | function! jekyll#buffer_setup() 56 | " TODO 57 | endfunction 58 | 59 | "" 60 | " @private 61 | " Set up commands that depend on Projectionist 62 | function! jekyll#projectionist_activate() 63 | for [root, value] in projectionist#query('type') 64 | if value ==# 'draft' 65 | return s:draft_buffer_setup() 66 | endif 67 | endfor 68 | endfunction 69 | 70 | " vim: fdm=marker:sw=2:sts=2:et 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-jekyll 2 | 3 | Vim extensions for Jekyll 2 sites. 4 | 5 | *Note: this is a prerelease version, which may change or break frequently.* 6 | 7 | 8 | 9 | ## Features 10 | 11 | Jekyll.vim provides conveniences for working with Jekyll 2 projects. It 12 | automatically detects Jekyll projects providing a set of commands available in 13 | Jekyll buffers: 14 | 15 | | Command | Description | 16 | |------------------------|-------------| 17 | | `:Epost {name}` ... | Quickly jump to or create posts with this family of commands including `:Epost`, `:Spost`, `:Vpost`, and `:Tpost`. Completion is provided. See [projectionist.vim][projectionist] for details. 18 | | `:Edraft {name}` ... | As above but for draft posts in `_drafts/` 19 | | `:Eplugin {name}` ... | As above but for Jekyll plug-ins in `_plugin` 20 | | `:Elayout {name}` ... | As above but for HTML layout files 21 | | `:Einclude {name}` ... | As above but for HTML include files 22 | | `:Econfig` ... | As above but for your `_config.yml` file 23 | | `:Publish` | Publish a draft post to your `_posts/` directory, automatically prepending the publish date to the file name | 24 | | `:Dispatch` | Build your site asynchronously via [dispatch.vim][dispatch] (it even acts intelligently in the presence of a Gemfile by running `bundle exec jekyll build`) | 25 | | `:Start` | Start up Jekyll's server in a shell via [dispatch.vim][dispatch] (it even acts intelligently in the presence of a Gemfile by running `bundle exec jekyll serve`) | 26 | 27 | ### Planned Features 28 | 29 | - A `:Jekyll` wrapper around the command-line utility with completion 30 | - A `:Slug` command to update the current post's slug based on the `title` in the YAML frontmatter 31 | - Templates for new posts and drafts 32 | - A test suite 33 | 34 | ## Installation 35 | 36 | ### Dependencies 37 | 38 | - [projectionist.vim][projectionist] provides the `:Epost` family of commands and file templates 39 | - (optional) [dispatch.vim][dispatch] provides asynchronous commands for building your Jekyll site 40 | - (optional) [liquid.vim][liquid] provides Liquid runtime files with Jekyll enhancements 41 | 42 | [projectionist]: https://github.com/tpope/vim-projectionist 43 | [dispatch]: https://github.com/tpope/vim-dispatch 44 | [liquid]: https://github.com/tpope/vim-liquid 45 | 46 | ## Development 47 | 48 | ### Testing 49 | 50 | Tests are written for [vspec][vspec], which can be installed via 51 | [vim-flavor][vim-flavor]: 52 | 53 | bundle install 54 | vim-flavor install 55 | 56 | The test suite can then be run via the rake task: 57 | 58 | rake test 59 | 60 | ### Documentation 61 | 62 | The documentation in `doc/` is generated from the plug-in source code via 63 | [vimdoc][vimdoc]. Do not edit `doc/jekyll.txt` directly. Refer to the 64 | existing inline documentation as a guide for documenting new code. 65 | 66 | The help doc can be rebuilt by running: 67 | 68 | rake doc 69 | 70 | [buildimg]: https://travis-ci.org/noahfrederick/vim-jekyll.png?branch=master 71 | [vspec]: https://github.com/kana/vim-vspec 72 | [vim-flavor]: https://github.com/kana/vim-flavor 73 | [vimdoc]: https://github.com/google/vimdoc 74 | -------------------------------------------------------------------------------- /doc/jekyll.txt: -------------------------------------------------------------------------------- 1 | *jekyll.txt* Vim extensions for Jekyll 2 sites 2 | Noah Frederick *Jekyll.vim* *jekyll* 3 | 4 | ============================================================================== 5 | CONTENTS *jekyll-contents* 6 | 1. Introduction...............................................|jekyll-intro| 7 | 2. Configuration.............................................|jekyll-config| 8 | 3. Commands................................................|jekyll-commands| 9 | 4. Functions..............................................|jekyll-functions| 10 | 5. About......................................................|jekyll-about| 11 | 12 | ============================================================================== 13 | INTRODUCTION *jekyll-intro* 14 | 15 | Jekyll.vim provides conveniences for working with Jekyll 2 projects. Some 16 | features include: 17 | 18 | * A :Jekyll wrapper around the command-line utility with completion 19 | * A :Publish command to publish your drafts 20 | * Projections via projectionist.vim, which provide :Epost, :Edraft, etc. 21 | * Optional integration with dispatch.vim 22 | 23 | This plug-in is only available if 'compatible' is not set. 24 | 25 | ============================================================================== 26 | CONFIGURATION *jekyll-config* 27 | 28 | *g:jekyll_post_ext* 29 | The file extension to use for posts 30 | 31 | Default: ".md" 32 | 33 | *g:jekyll_dispatch* 34 | The :Dispatch command to run in Jekyll buffers 35 | 36 | Default: "jekyll build" ("bundle exec jekyll build" if a Gemfile is present) 37 | 38 | *g:jekyll_start* 39 | The :Start command to run in Jekyll buffers 40 | 41 | Default: "jekyll serve" ("bundle exec jekyll serve" if a Gemfile is present) 42 | 43 | ============================================================================== 44 | COMMANDS *jekyll-commands* 45 | 46 | :[N]Publish *:Publish* 47 | Publish the current draft post (only available in draft buffers). 48 | 49 | This command moves the current buffer's file from the _drafts/ directory to 50 | the _posts/ directory and prepends the current date as the published date. 51 | 52 | ============================================================================== 53 | FUNCTIONS *jekyll-functions* 54 | 55 | jekyll#version() *jekyll#version()* 56 | Get the version number of Jekyll.vim (e.g., '1.0.0') 57 | 58 | ============================================================================== 59 | ABOUT *jekyll-about* 60 | 61 | Jekyll.vim is distributed under the same terms as Vim itself (see |license|) 62 | 63 | You can find the latest version of this plug-in on GitHub: 64 | https://github.com/noahfrederick/vim-jekyll 65 | 66 | Please report issues on GitHub as well: 67 | https://github.com/noahfrederick/vim-jekyll/issues 68 | 69 | 70 | vim:tw=78:ts=8:ft=help:norl: 71 | -------------------------------------------------------------------------------- /plugin/jekyll.vim: -------------------------------------------------------------------------------- 1 | " plugin/jekyll.vim - Detect a Jekyll project 2 | " Maintainer: Noah Frederick (http://noahfrederick.com) 3 | 4 | "" 5 | " @section Introduction, intro 6 | " @stylized Jekyll.vim 7 | " @plugin(stylized) provides conveniences for working with Jekyll 2 8 | " projects. Some features include: 9 | " 10 | " * A :Jekyll wrapper around the command-line utility with completion 11 | " * A :Publish command to publish your drafts 12 | " * Projections via projectionist.vim, which provide :Epost, :Edraft, etc. 13 | " * Optional integration with dispatch.vim 14 | " 15 | " This plug-in is only available if 'compatible' is not set. 16 | 17 | "" 18 | " @section About, about 19 | " @plugin(stylized) is distributed under the same terms as Vim itself (see 20 | " |license|) 21 | " 22 | " You can find the latest version of this plug-in on GitHub: 23 | " https://github.com/noahfrederick/vim-@plugin(name) 24 | " 25 | " Please report issues on GitHub as well: 26 | " https://github.com/noahfrederick/vim-@plugin(name)/issues 27 | 28 | if (exists('g:loaded_jekyll') && g:loaded_jekyll) || &cp 29 | finish 30 | endif 31 | let g:loaded_jekyll = 1 32 | 33 | " Detection {{{ 34 | 35 | "" 36 | " Determine whether the current or supplied [path] belongs to a Kohana project 37 | function! s:jekyll_detect(...) abort 38 | if exists('b:jekyll_root') 39 | return 1 40 | endif 41 | 42 | let fn = fnamemodify(a:0 ? a:1 : expand('%'), ':p') 43 | 44 | if !isdirectory(fn) 45 | let fn = fnamemodify(fn, ':h') 46 | endif 47 | 48 | let config = findfile('_config.yml', escape(fn, ', ') . ';') 49 | 50 | if !empty(config) 51 | let b:jekyll_root = fnamemodify(config, ':p:h') 52 | let b:jekyll_has_bundler = filereadable(b:jekyll_root . '/Gemfile') 53 | return 1 54 | endif 55 | endfunction 56 | 57 | " }}} 58 | " Initialization {{{ 59 | 60 | if !exists('g:jekyll_post_ext') 61 | "" 62 | " The file extension to use for posts 63 | " 64 | " Default: ".md" 65 | let g:jekyll_post_ext = '.md' 66 | endif 67 | 68 | augroup jekyll_detect 69 | autocmd! 70 | " Project detection 71 | autocmd BufNewFile,BufReadPost * 72 | \ if s:jekyll_detect(expand(":p")) && empty(&filetype) | 73 | \ call jekyll#buffer_setup() | 74 | \ endif 75 | autocmd VimEnter * 76 | \ if empty(expand("")) && s:jekyll_detect(getcwd()) | 77 | \ call jekyll#buffer_setup() | 78 | \ endif 79 | autocmd FileType * if s:jekyll_detect() | call jekyll#buffer_setup() | endif 80 | augroup END 81 | 82 | " }}} 83 | " Projections {{{ 84 | 85 | if !exists('g:jekyll_dispatch') 86 | "" 87 | " The :Dispatch command to run in Jekyll buffers 88 | " 89 | " Default: "jekyll build" ("bundle exec jekyll build" if a Gemfile is 90 | " present) 91 | let g:jekyll_dispatch = 'jekyll build' 92 | endif 93 | 94 | if !exists('g:jekyll_start') 95 | "" 96 | " The :Start command to run in Jekyll buffers 97 | " 98 | " Default: "jekyll serve" ("bundle exec jekyll serve" if a Gemfile is 99 | " present) 100 | let g:jekyll_start = 'jekyll serve' 101 | endif 102 | 103 | " Ensure that projectionist gets loaded first 104 | if !exists('g:loaded_projectionist') 105 | runtime! plugin/projectionist.vim 106 | endif 107 | 108 | function! s:projectionist_detect() 109 | if s:jekyll_detect(get(g:, 'projectionist_file', '')) 110 | if b:jekyll_has_bundler && g:jekyll_dispatch =~# '^jekyll ' 111 | let b:jekyll_dispatch = 'bundle exec ' . g:jekyll_dispatch 112 | else 113 | let b:jekyll_dispatch = g:jekyll_dispatch 114 | endif 115 | 116 | if b:jekyll_has_bundler && g:jekyll_start =~# '^jekyll ' 117 | let b:jekyll_start = 'bundle exec ' . g:jekyll_start 118 | else 119 | let b:jekyll_start = g:jekyll_start 120 | endif 121 | 122 | call projectionist#append(b:jekyll_root, { 123 | \ "*": { 124 | \ "start": b:jekyll_start, 125 | \ "dispatch": b:jekyll_dispatch, 126 | \ "framework": "jekyll", 127 | \ }, 128 | \ "README.md": { 129 | \ "type": "doc", 130 | \ }, 131 | \ "_plugins/*.rb": { 132 | \ "type": "plugin", 133 | \ }, 134 | \ "_layouts/*.html": { 135 | \ "type": "layout", 136 | \ }, 137 | \ "_includes/*.html": { 138 | \ "type": "include", 139 | \ }, 140 | \ "_posts/*": { 141 | \ "type": "post", 142 | \ }, 143 | \ "_drafts/*": { 144 | \ "type": "draft", 145 | \ }, 146 | \ "_config.yml": { 147 | \ "type": "config", 148 | \ }}) 149 | endif 150 | endfunction 151 | 152 | augroup jekyll_projections 153 | autocmd! 154 | autocmd User ProjectionistDetect call s:projectionist_detect() 155 | autocmd User ProjectionistActivate call jekyll#projectionist_activate() 156 | augroup END 157 | 158 | " }}} 159 | " vim: fdm=marker:sw=2:sts=2:et 160 | --------------------------------------------------------------------------------