relocate emoji plugin, stop pre-compiling assets

This commit is contained in:
Sam 2013-11-20 14:38:21 +11:00
parent a468d6cfb0
commit 8278fdb9dd
1748 changed files with 181 additions and 404 deletions

14
Gemfile
View File

@ -120,16 +120,6 @@ gem 'diffy', '>= 3.0', require: false
gem 'highline', require: false
gem 'rack-protection' # security
# Gem that enables support for plugins. It is required.
gem 'discourse_plugin', path: 'vendor/gems/discourse_plugin'
# Discourse Plugins (optional)
# Polls and Tasks have been disabled for launch, we need think all sorts of stuff through before adding them back in
# biggest concern is core support for custom sort orders, but there is also styling that just gets mishmashed into our core theme.
# gem 'discourse_poll', path: 'vendor/gems/discourse_poll'
gem 'discourse_emoji', path: 'vendor/gems/discourse_emoji'
# gem 'discourse_task', path: 'vendor/gems/discourse_task'
# Gems used only for assets and not required
# in production environments by default.
# allow everywhere for now cause we are allowing asset debugging in prd
@ -172,7 +162,9 @@ group :development do
gem 'annotate', :git => 'https://github.com/SamSaffron/annotate_models.git'
end
# Gem that enables support for plugins. It is required.
# TODO: does this really need to be a gem ?
gem 'discourse_plugin', path: 'vendor/gems/discourse_plugin'
# this is an optional gem, it provides a high performance replacement
# to String#blank? a method that is called quite frequently in current

View File

@ -87,11 +87,6 @@ GIT
specs:
email_reply_parser (0.6)
PATH
remote: vendor/gems/discourse_emoji
specs:
discourse_emoji (0.0.1)
PATH
remote: vendor/gems/discourse_plugin
specs:
@ -469,7 +464,6 @@ DEPENDENCIES
binding_of_caller
certified
diffy (>= 3.0)
discourse_emoji!
discourse_plugin!
email_reply_parser!
ember-rails

View File

@ -154,7 +154,7 @@ class Plugin::Instance
end
unless assets.blank?
assets.each do |asset|
if asset =~ /\.js$/
if asset =~ /\.js$|.js.erb$/
DiscoursePluginRegistry.javascripts << asset
elsif asset =~ /\.css$|\.scss$/
DiscoursePluginRegistry.stylesheets << asset
@ -171,6 +171,15 @@ class Plugin::Instance
DiscoursePluginRegistry.server_side_javascripts << js
end
end
public_data = File.dirname(path) + "/public"
if Dir.exists?(public_data)
target = Rails.root.to_s + "/public/plugins/"
`mkdir -p #{target}`
target << name
# TODO a cleaner way of registering and unregistering
`ln -s #{public_data} #{target}` unless File.exists? target
end
end
def auth_provider(opts)
@ -206,7 +215,7 @@ class Plugin::Instance
end
else
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
exit -1
exit(-1)
end
end

View File

@ -80,7 +80,13 @@ module PrettyText
# Load server side javascripts
if DiscoursePluginRegistry.server_side_javascripts.present?
DiscoursePluginRegistry.server_side_javascripts.each do |ssjs|
ctx.load(ssjs)
if(ssjs =~ /\.erb/)
erb = ERB.new(File.read(ssjs))
erb.filename = ssjs
ctx.eval(erb.result)
else
ctx.load(ssjs)
end
end
end
@ -167,8 +173,8 @@ module PrettyText
def self.add_rel_nofollow_to_user_content(html)
whitelist = []
l = SiteSetting.exclude_rel_nofollow_domains
whitelist = l.split(",") if l.present?
domains = SiteSetting.exclude_rel_nofollow_domains
whitelist = domains.split(",") if domains.present?
site_uri = nil
doc = Nokogiri::HTML.fragment(html)

View File

@ -0,0 +1,146 @@
(function() {
var emoji = <%= Dir.glob(File.expand_path("../../../public/images/*.png", __FILE__)).map{|f| File.basename(f).split(".")[0]}.inspect %>;
function imageFor(code) {
if (emoji.indexOf(code) !== -1) {
var url = Discourse.getURL('/plugins/emoji/images/' + code + '.png');
return ['img', {href: url, title: ':' + code + ':', 'class': 'emoji', alt: code}];
}
}
// Also support default emotions
var translations = {
':)' : 'smile',
':-)' : 'smile',
':(' : 'frowning',
':-(' : 'frowning',
';)' : 'wink',
';-)' : 'wink',
':\'(' : 'cry',
':\'-(' : 'cry',
':-\'(' : 'cry',
':p' : 'stuck_out_tongue',
':P' : 'stuck_out_tongue',
':-P' : 'stuck_out_tongue',
':O' : 'open_mouth',
':-O' : 'open_mouth',
':D' : 'grin',
':-D' : 'grin',
':|' : 'expressionless',
':-|' : 'expressionless',
";P" : 'stuck_out_tongue_winking_eye',
";-P" : 'stuck_out_tongue_winking_eye',
';)' : 'wink',
';-)' : 'wink',
":$" : 'blush',
":-$" : 'blush'
};
var translationsWithColon = {};
Object.keys(translations).forEach(function (t) {
if (t[0] === ':') {
translationsWithColon[t] = translations[t];
} else {
var replacement = translations[t];
Discourse.Dialect.inlineReplace(t, function () {
return imageFor(replacement);
});
}
});
function escapeRegExp(s) {
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
}
var translationColonRegexp = new RegExp("^" +
Object.keys(translationsWithColon).map(function (t) {
return "(" + escapeRegExp(t) + ")";
}).join("|")
);
Discourse.Dialect.registerInline(':', function(text, match, prev) {
var endPos = text.indexOf(':', 1),
contents;
// If there is no trailing colon, check our translations that begin with colons
if (endPos === -1) {
translationColonRegexp.lastIndex = 0;
var match = translationColonRegexp.exec(text);
if (match && match[0]) {
contents = imageFor(translationsWithColon[match[0]]);
if (contents) {
return [match[0].length, contents];
}
}
return;
}
// Simple find and replace from our array
var between = text.slice(1, endPos);
contents = imageFor(between);
if (contents) {
return [endPos+1, contents];
}
});
if (Discourse && Discourse.ComposerView) {
Discourse.ComposerView.on("initWmdEditor", function(event){
var baseUrl = Discourse.getURL("/");
template = Handlebars.compile("<div class='autocomplete'>" +
"<ul>" +
"{{#each options}}" +
"<li>" +
"<a href='#'>" +
"<img src='" + baseUrl + "plugins/emoji/images/{{this}}.png' class='emoji'> " +
"{{this}}</a>" +
"</li>" +
"{{/each}}" +
"</ul>" +
"</div>");
$('#wmd-input').autocomplete({
template: template,
key: ":",
transformComplete: function(v){ return v + ":"; },
dataSource: function(term){
var full = ":" + term;
term = term.toLowerCase();
if (term === "") {
return Ember.RSVP.resolve(["smile", "smiley", "wink", "sunny", "blush"]);
}
if (translations[full]) {
return Ember.RSVP.resolve([translations[full]]);
}
var options = [];
var i;
for (i=0; i < emoji.length; i++) {
if (emoji[i].indexOf(term) === 0) {
options.push(emoji[i]);
if(options.length > 4) { break; }
}
}
if (options.length <= 4) {
for (i=0; i < emoji.length; i++) {
if (emoji[i].indexOf(term) > 0) {
options.push(emoji[i]);
if(options.length > 4) { break; }
}
}
}
return Ember.RSVP.resolve(options);
}
});
});
}
Discourse.Markdown.whiteListClass("emoji");
}).call(this);

View File

@ -0,0 +1,5 @@
body img.emoji {
width: 20px;
height: 20px;
vertical-align: middle;
}

7
plugins/emoji/plugin.rb Normal file
View File

@ -0,0 +1,7 @@
# name: emoji
# about: emoji support for Discourse
# version: 0.1
# authors: Sam Saffron, Robin Ward
register_asset('javascripts/emoji.js.erb', :server_side)
register_asset('stylesheets/emoji.css')

Some files were not shown because too many files have changed in this diff Show More