Permalink
Browse files

change partial that the path is relative to the script directory

except in cases when it contains "/"; then it's considered absolute
  • Loading branch information...
1 parent 388954b commit 8117be2dd9ef40daf93d8c39f150c50f53fccb6d @mislav committed Jun 3, 2009
Showing with 26 additions and 11 deletions.
  1. +23 −8 Thorfile
  2. +3 −3 endless_tweets/endless_tweets.js
View
@@ -12,10 +12,11 @@ class Gm < Thor
for line in source
case line
- when %r{(\s*)//= (\w+)}
- helper_name = $2
- target.puts "/*** #{helper_name} ***/"
- target.write File.read("toolkit/#{helper_name}.js")
+ when %r{(\s*)//= ([\w/.]+)}
+ indentation, partial_name = $1, $2
+ partial = normalize_partial_path(partial_name, name)
+ target.puts "/*** #{partial} ***/"
+ target.write read_partial(partial, indentation)
else
target.write line
end
@@ -71,6 +72,14 @@ class Gm < Thor
)
end
+ def self.scripts
+ @@scripts ||= {
+ 'endless_tweets' => 24398
+ }
+ end
+
+ private
+
def script_path(id)
"/scripts/source/#{id}.user.js"
end
@@ -79,9 +88,15 @@ class Gm < Thor
"#{name}/#{name}.user.js"
end
- def self.scripts
- @@scripts ||= {
- 'endless_tweets' => 24398
- }
+ def normalize_partial_path(path, script_name)
+ if path.index('/')
+ path
+ else
+ "#{script_name}/#{path}"
+ end
+ end
+
+ def read_partial(path, indentation = nil)
+ source = File.read(path)
end
end
@@ -8,7 +8,7 @@
(function(realWindow){
-//= gm_functions
+//= toolkit/gm_functions.js
var timeline = $('timeline'),
jQuery = realWindow.jQuery,
@@ -628,7 +628,7 @@ if (address && /[+-]?\d+\.\d+,[+-]?\d+\.\d+/.test(address.textContent)) {
address.innerHTML = '<a class="googlemap" href="http://maps.google.com/maps?q=' + coordinates + '"><img src="http://maps.google.com/staticmap?center=' + coordinates + '&markers=' + coordinates + ',red&zoom=13&size=165x165&key=' + API_KEY + '" alt=""></a>'
}
-//= update_notifier
+//= toolkit/update_notifier.js
var scriptURL = 'http://userscripts.org/scripts/show/24398',
sidebar = $('side'),
@@ -666,7 +666,7 @@ if (wrapper) checkUserscriptUpdate(scriptURL, scriptLength, function() {
")
})
-//= toolkit
+//= toolkit/toolkit.js
function twitterLinkify(text) {
return linkify(text).replace(/(^|\W)@(\w+)/g, '$1@<a href="/$2">$2</a>')

0 comments on commit 8117be2

Please sign in to comment.