Git Product home page Git Product logo

Comments (3)

sbdchd avatar sbdchd commented on July 28, 2024

Just to clarify, you want :Neoformat to run bundle exec ruby-beautify instead of ruby-beautify if a Gemfile is present?

Note: I don't have much experience with ruby

from neoformat.

mattes avatar mattes commented on July 28, 2024

That is correct. Unsure what the best approach would be, especially if you are in a child directory somewhere and you'd need to traverse the parent directories to find if a Gemfile is present somewhere.

from neoformat.

sbdchd avatar sbdchd commented on July 28, 2024

This is what I have so far. It would be great if you could check that it works for you!

Neoformat finds and checks the gem file with the regex ^gem .ruby-beautify. and uses bundle exec ruby-beautify instead of ruby-beautify if present.

diff --git a/autoload/neoformat.vim b/autoload/neoformat.vim
index 7157f97..ebdc8b1 100644
--- a/autoload/neoformat.vim
+++ b/autoload/neoformat.vim
@@ -192,7 +192,10 @@ function! s:generate_cmd(definition, filetype) abort
         call neoformat#utils#log('no exe field in definition')
         return {}
     endif
-    if !executable(executable)
+
+    " check if executable is executable, need to split and take first
+    " executbale for cases such as 'bundle exec ruby-beautify'
+    if !executable(split(executable)[0])
         call neoformat#utils#log('executable: ' . executable . ' is not an executable')
         return {}
     endif
diff --git a/autoload/neoformat/formatters/ruby.vim b/autoload/neoformat/formatters/ruby.vim
index ae09bfe..ce32bb8 100644
--- a/autoload/neoformat/formatters/ruby.vim
+++ b/autoload/neoformat/formatters/ruby.vim
@@ -3,8 +3,24 @@ function! neoformat#formatters#ruby#enabled() abort
 endfunction
 
 function! neoformat#formatters#ruby#rubybeautify() abort
-     return {
+    let definition = {
         \ 'exe': 'ruby-beautify',
         \ 'args': ['--spaces', '-c ' . shiftwidth()],
         \ }
+
+    let gemfile_lines = readfile(findfile('Gemfile', '.:'))
+
+    let use_bundle = 0
+    for l in gemfile_lines
+        if l =~# "^gem .ruby-beautify."
+            let use_bundle = 1
+            break
+        endif
+    endfor
+
+    if use_bundle
+        let definition.exe = 'bundle exec ruby-beautify'
+    endif
+
+    return definition
 endfunction

from neoformat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.