Code Monkey home page Code Monkey logo

code_web's Introduction

CodeWeb

This uses ruby parser to read code with static analysis and find references. Works best when looking for finding static methods that possibly span multiple lines

It is not smart enough to understand return types.

For hashes/positional arguments, it displays the hash arguments. It only works when actual hash parameters are passed vs variables or splats.

It generates an html file with the list of each method and the invocations. Each reference has a url to the place in code where it is found.

The urls use textmate url format, which also works with sublime. I use lincastor on my machine to wire the urls to the actual editor, so any program will do.

Installation

Add this line to your application's Gemfile:

gem 'code_web'

And then execute:

$ bundle

Or install it yourself as:

$ gem install code_web

Usage

# if you find the reference in a file named miq_queue.rb, then color the url with #999
# if you find the reference in a file with the director tools, then color the url with #ccc 
# look for the class name MiqQueue
# look in the directories app, tools, and lib
# output the report to miq_queue.html (in html format)

$ code_web -p 'miq_queue.rb$=#999' -p 'tools/=#ccc' 'MiqQueue\b' app tools lib -o miq_queue.html


# find calls to User.select
$ code_web 'User.select\b' lib -o user_select.html


# generate links pointing to github (instead of local sublime)
$ code_web --url https://github.com/ManageIQ/manageiq/blob/master --byebug 'MiqQueue' app lib/vmdb -o miq_queue.html

Url handline

Currently, this generates urls using the textmate file protocol.

I use LinCastor to map the url to my editor of choice, sublime. But there are many tools that will do this for you. LinCastor has worked for many many years, including my current version, 10.12.3

I use the following script to wire it together:

#!/usr/bin/ruby

# Parse a url according to 
# http://blog.macromates.com/2007/the-textmate-url-scheme/
# opens the file

SUBL_PATH="/Applications/Sublime Text.app"
SUBL_BIN_PATH="#{SUBL_PATH}/Contents/SharedSupport/bin/subl"

#require 'logger'
require 'uri'
require 'cgi'

#DEBUG = Logger.new(File.open("#{ENV['HOME']}/sublime_cmd.txt", File::WRONLY | File::APPEND|File::CREAT))

subl_url=ENV['URL']
p=CGI.parse(URI.parse(subl_url).query)
subl_file="#{p["url"].first[7..-1]}:#{p["line"].first}"

#DEBUG.info(subl_file)

ret=`"#{SUBL_BIN_PATH}" "#{subl_file}"`
#DEBUG.info("#{SUBL_BIN_PATH} #{subl_file}")
#DEBUG.info("/handle_url")

exit 0 # the handler has finished successfully

I left the debugging statements in there to help you if there are issues

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

code_web's People

Contributors

kbrock avatar

Watchers

 avatar  avatar  avatar

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.