Skip to content

Commit

Permalink
finished
Browse files Browse the repository at this point in the history
  • Loading branch information
jlbfalcao committed Aug 12, 2010
1 parent a8d3535 commit c564978
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 14 deletions.
42 changes: 31 additions & 11 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
= mozrepl_tools

Description goes here.

== Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.
Reload css or js (and Ext.component) through your editor. Thanks to MozRepl :)

== Before install

install MozRepl
http://wiki.github.com/bard/mozrepl/

== Install

gem install mozrepl_tools

== Reload css (<link /> tag only)

#> mozrepl 'main.css'

== Adding a js file to current tab

#> mozrepl 'my/path/file.js'

It's works with Sencha(ExtJS) Components!!!

== Using with Textmate (~/Library/Application Support/TextMate/Bundles/MozRepl.tmbundle)

#> mozrepl textmate

And now, use "Command+Shif+R" (like magic)

== TODO

#TODO: use watchr to reload automatic

== Copyright

Copyright (c) 2010 Jorge Falcão. See LICENSE for details.

7 changes: 4 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "mozrepl_tools"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.summary = %Q{Some mozrepl tools}
gem.description = %Q{}
gem.files = FileList['lib/**/*']
gem.email = "jlbfalcao@gmail.com"
gem.homepage = "http://github.com/jlbfalcao/mozrepl_tools"
gem.authors = ["Jorge Falcão"]
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
# gem.add_development_dependency "watchr", ">= 0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
16 changes: 16 additions & 0 deletions bin/mozrepl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

if ARGV[0] == 'textmate'
puts "textmate plugin ok!"
textmate = File.expand_path("~/Library/Application Support/TextMate/Bundles/MozRepl.tmbundle")

basedir = File.join(File.dirname(File.dirname(__FILE__)))

bundle = File.join basedir, 'lib', 'textmate'

File.unlink(textmate)
File.symlink(bundle, textmate)
system %Q{osascript -e 'tell app "TextMate" to reload bundles'}
exit
end

require 'mozrepl_tools'
5 changes: 5 additions & 0 deletions lib/mozrepl_tools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

pwd = File.dirname(__FILE__)

puts "ruby '#{pwd}/textmate/Support/lib/mozrepl_tools.rb' #{ARGV[0]}"
system("ruby '#{pwd}/textmate/Support/lib/mozrepl_tools.rb' #{ARGV[0]}")
24 changes: 24 additions & 0 deletions lib/textmate/Commands/repl.tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>command</key>
<string>#!/usr/bin/env sh
${TM_RUBY:-ruby} "$TM_BUNDLE_SUPPORT/lib/mozrepl_tools.rb"
</string>
<key>fallbackInput</key>
<string>document</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>@R</string>
<key>name</key>
<string>Reload Using MozRepl</string>
<key>output</key>
<string>showAsTooltip</string>
<key>uuid</key>
<string>E36D6544-2445-4B6B-82FF-61B233ED7901</string>
</dict>
</plist>
100 changes: 100 additions & 0 deletions lib/textmate/Support/lib/mozrepl_tools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

require 'socket'

s = TCPSocket.open('localhost', 4242)

script = DATA.read

filepath = ENV["TM_FILEPATH"] || ARGV[0]
file = File.basename filepath
ext = File.extname filepath
filename = File.expand_path filepath
# p ext
s.puts(script)

if ext == ".css"
s.puts("reload.css('#{file}')")
puts "reloaded #{file}"
elsif ext == ".js"
s.puts("reload.js('#{filename}')")
puts "reloaded #{filename}"
end

# puts script

# workaround
sleep 1

s.close

__END__


var reload = (function(content, window) {
var window = (function() {
for ( var i = 0; i < window.length; i++ ) {
if ( content.location == window[i].location ) {
return window[i];
}
}
})();

var document = doc = window.document;
var Ext = window.Ext;

// firebug
var console = window.console || {debug:function(){}};

console.debug("loading...");

// add development Ext.reg
if ( ! Ext._reg ) {
console.debug('saving original Ext.reg');
Ext._reg = Ext.reg;
}

Ext.reg = function(xtype) {
console.debug("Ext.reg:", arguments);
// calling old Ext.reg
Ext._reg.apply(Ext, arguments);

// reinstance all xtypes
var items = Ext.ComponentMgr.all.filterBy(function(e) { return e.getXType() == xtype }).each(function(item) {
repl.print(item)
var ic = item.initialConfig;
var o = item.ownerCt;
o.remove(item);
var it = o.add(ic)
if ( o.getLayout().setActiveItem ) {
o.getLayout().setActiveItem(it);
};
o.doLayout();
});
};

var head = document.getElementsByTagName("head")[0];

return {
css:function(file) {
var l = doc.getElementsByTagName('link');
for ( var i = 0; i < l.length; i++ ) {
var ss = l[i];
console.debug("reloading:", ss);
if ( ss.href && ss.href.indexOf(file) != -1 ) {
try {
ss.href = (ss.href.split("?")[0]) + "?" + Math.random();
} catch (e) {
repl.print(e);
}
}
}
},
js:function(filename) {
var script = document.createElement('script');
script.type = "text/javascript";
script.src = filename;
repl.print(filename);
head.appendChild(script);
}
};
})(content, window);
10 changes: 10 additions & 0 deletions lib/textmate/info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>MozRepl</string>
<key>uuid</key>
<string>16A1485C-204A-4160-9B43-541DD45E4386</string>
</dict>
</plist>

0 comments on commit c564978

Please sign in to comment.