Skip to content

Commit

Permalink
Setting up base version of view partial finder gem
Browse files Browse the repository at this point in the history
Adding README
  • Loading branch information
sairam committed Jul 22, 2012
1 parent 58e1c96 commit 4dc8899
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in view_finder.gemspec
gemspec
8 changes: 8 additions & 0 deletions LICENSE
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2012 Sairam Kunala

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 changes: 35 additions & 3 deletions README.md
@@ -1,4 +1,36 @@
view-finder
===========
# view-finder

## Description
Open view partials from a live rails site into your favorite text editor.

Only TextMate is supported right now with the uri (txmt://) on a Mac . (Pull requests welcome for getting your favorite editor configured)

## Idea Motivation
A project spans across many developers across many months. Some developers use their own convention for partials and some times partials, or even sometimes its your code you wrote couple of months back. Its painfully slow to jump through files and you might not want to dig deep for the right partial doing the job of displaying the information.

## DISCLAIMER / NOTE
* Make sure this gem is not included in the environment where you are exposing the site to public since this would reveal the filenames which you are using.
* I am not responsible when using of this gem causes any kind of loss or exposing filenames from within the project.

## Setting up(read the DISCLAIMER first before setting up the gem)
* Include `gem 'view-finder', group: :development, git: 'https://github.com/sairam/view_finder.git'` in Gemfile to only allow this gem in development mode (see the DISCLAIMER on why I stress about only using it in development mode)
* Run `bundle install` to pull the gem.

### When Asset Pipeline is enabled
* Include `view_finder` in application.js (When asset pipeline is enabled)

### When Asset Pipeline is not enabled *(not supported yet)*
* Run `rails g view_finder g:install` to copy from the static javascripts to public/ directory

## Make *it* work (will be provided with a UI element to be toggled)
* Open the javascript console and type in `window.openFileMode=true` and click on any element and it opens the partial file in textmate.
* To stop the opening files type in `window.openFileMode=false`

## Works with
* Rails 3+ (with asset pipeline enabled)
* Tested with Chrome

## Upgrading
### Required only when Asset Pipeline is enabled *(not supported yet)*
* Run `rails g view_finder g:install` to copy from the static javascripts to public/ directory

Open view partials from a live rails site into your favorite text editor
1 change: 1 addition & 0 deletions Rakefile
@@ -0,0 +1 @@
require "bundler/gem_tasks"
26 changes: 26 additions & 0 deletions lib/generators/view_finder/install/install_generator.rb
@@ -0,0 +1,26 @@
module ViewFinder
# Copies formtastic.css to public/stylesheets/ (Rails 3.0.x only) and a config initializer
#
# @example
# $ rails generate view_finder:install
#
# @todo Test with Rails 3.0
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../../../templates', __FILE__)
class_option :template_engine

unless ::Rails.config.assets.enabled
# Asset pipeline is not enabled - Lets copy the javascripts
desc "Copies all JS files to public/javascripts/"
def copy_files
template '../../../vendor/assets/javascripts/formtastic.css', 'public/javascripts/formtastic.css'
template '../../../vendor/assets/javascripts/formtastic_ie6.css', 'public/javascripts/formtastic_ie6.css'
end
end

def copy_scaffold_template
engine = options[:template_engine]
copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
end
end
end
10 changes: 10 additions & 0 deletions lib/view_finder.rb
@@ -0,0 +1,10 @@
require "view_finder/version"
require 'view_finder/partial_renderer'
module ViewFinder
# Your code goes here...

class Engine < ::Rails::Engine
end

end

11 changes: 11 additions & 0 deletions lib/view_finder/partial_renderer.rb
@@ -0,0 +1,11 @@
module ::ActionView
class PartialRenderer < AbstractRenderer
alias :render_orig :render
def render(context, options, block)
setup(context, options, block)
file_path = find_partial.inspect
span_tag = "<span style='display:none' class='the-real-file-path' data-uri='file://#{Rails.root.join file_path}'></span>".html_safe if file_path =~ /\.html/
render_orig(context, options, block) + span_tag
end
end
end
3 changes: 3 additions & 0 deletions lib/view_finder/version.rb
@@ -0,0 +1,3 @@
module ViewFinder
VERSION = "0.0.1"
end
2 changes: 2 additions & 0 deletions vendor/assets/javascripts/depth.js.coffee
@@ -0,0 +1,2 @@
$.fn.depth = ->
$(this).parents().length
46 changes: 46 additions & 0 deletions vendor/assets/javascripts/view_finder.js.coffee
@@ -0,0 +1,46 @@
#= require 'depth'

window._xViewFinder ?= {}

$(()->
_xViewFinder._xBasics.init();
)

_xViewFinder._xBasics =
init: () ->
@className = ".the-real-file-path"
@prevDate = Date.now()
window.filesList = {}

$(document).ready ->
# since we are adding
eleName="span.the-real-file-path"
$(eleName).prevUntil(eleName).click (e) ->
a = $(this)
if window.openFileMode is true
e.preventDefault()
element = a.nextAll(eleName).first()
file = element.attr("data-uri")
console.log(file)
window.filesList[file] = element.depth()
_xViewFinder._xBasics.jsTimeout()

fileDisplay: () ->
highestDepth = 0
reqkey = ""
filesList = window.filesList
# window.openFilePrefix ? window.openFilePrefix :
openFilePrefix = 'txmt://open/?url='
for key of filesList
if highestDepth < filesList[key]
highestDepth = filesList[key]
reqkey = key
console.log(reqkey)
window.open openFilePrefix+reqkey, "ViewFinderGem","toolbar=no,menubar=0,status=0,copyhistory=0,scrollbars=yes,resizable=1,location=0,Width=200,Height=200"
window.filesList = {}

jsTimeout: () ->
if Date.now() - @prevDate > 2000
window.setTimeout "_xViewFinder._xBasics.fileDisplay()", 2000
@prevDate = Date.now()

25 changes: 25 additions & 0 deletions view_finder.gemspec
@@ -0,0 +1,25 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "view_finder/version"

Gem::Specification.new do |s|
s.name = "view_finder"
s.version = ViewFinder::VERSION
s.authors = ["Sairam Kunala"]
s.email = ["sairam.kunala@gmail.com"]
s.homepage = ""
s.summary = %q{Open view partials from a live rails site into your favorite text editor}
s.description = %q{Open view partials from a live rails site into your favorite text editor}

s.rubyforge_project = "view_finder"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
# s.add_runtime_dependency 'gem_name'
s.add_runtime_dependency 'coffee-rails'
end

0 comments on commit 4dc8899

Please sign in to comment.