mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 12:14:36 +08:00
Initial release of Discourse
This commit is contained in:
5
vendor/gems/discourse_poll/lib/discourse_poll.rb
vendored
Normal file
5
vendor/gems/discourse_poll/lib/discourse_poll.rb
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
require 'discourse_poll/version'
|
||||
require 'discourse_poll/engine' if defined?(Rails) && (!Rails.env.test?)
|
||||
|
||||
|
||||
I18n.load_path << "#{File.dirname(__FILE__)}/discourse_poll/locale/en.yml"
|
21
vendor/gems/discourse_poll/lib/discourse_poll/engine.rb
vendored
Normal file
21
vendor/gems/discourse_poll/lib/discourse_poll/engine.rb
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
require 'discourse_poll/plugin'
|
||||
|
||||
module DiscoursePoll
|
||||
class Engine < Rails::Engine
|
||||
|
||||
engine_name 'discourse_poll'
|
||||
|
||||
initializer "discourse_poll.configure_rails_initialization" do |app|
|
||||
|
||||
app.config.after_initialize do
|
||||
DiscoursePluginRegistry.setup(DiscoursePoll::Plugin)
|
||||
end
|
||||
|
||||
app.config.to_prepare do
|
||||
DiscoursePoll::Plugin.include_mixins
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
47
vendor/gems/discourse_poll/lib/discourse_poll/locale/en.yml
vendored
Normal file
47
vendor/gems/discourse_poll/lib/discourse_poll/locale/en.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
en:
|
||||
|
||||
js:
|
||||
poll:
|
||||
title: "Poll"
|
||||
description: "This topic is a poll. Vote for posts by clicking the vote button. Posts with the most votes will rise to the top!"
|
||||
|
||||
vote:
|
||||
voted: 'voted'
|
||||
title: 'vote'
|
||||
help: 'vote for this post'
|
||||
who_voted: 'click to see who voted for this option'
|
||||
cant: "Sorry, you've already voted."
|
||||
not_logged_in: "You must be logged in to vote."
|
||||
|
||||
topic_statuses:
|
||||
poll:
|
||||
help: "this topic is a poll"
|
||||
|
||||
topic:
|
||||
reply:
|
||||
poll: "Add Poll Option"
|
||||
|
||||
post:
|
||||
archetypes:
|
||||
poll:
|
||||
public: "Other users can see what you voted for."
|
||||
private: "Your vote will be kept private."
|
||||
single_vote: "You may only vote once."
|
||||
many_votes: "You may vote for as many options as you like."
|
||||
|
||||
post_action_types:
|
||||
vote:
|
||||
title: 'Vote'
|
||||
description: 'Vote for this post'
|
||||
long_form: 'voted for this post'
|
||||
|
||||
archetypes:
|
||||
poll:
|
||||
title: "Poll Topic"
|
||||
options:
|
||||
single_vote:
|
||||
title: "Only allow one vote"
|
||||
description: "A user may only vote on one post."
|
||||
private_poll:
|
||||
title: "Voting is Private"
|
||||
description: "Hide who voted for what choice."
|
49
vendor/gems/discourse_poll/lib/discourse_poll/plugin.rb
vendored
Normal file
49
vendor/gems/discourse_poll/lib/discourse_poll/plugin.rb
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
require 'discourse_plugin'
|
||||
|
||||
module DiscoursePoll
|
||||
class Plugin < DiscoursePlugin
|
||||
|
||||
MAX_SORT_ORDER = 2147483647
|
||||
POLL_OPTIONS = {private_poll: 1, single_vote: 1}
|
||||
|
||||
def setup
|
||||
|
||||
# Add our Assets
|
||||
register_js('discourse_poll')
|
||||
register_css('discourse_poll')
|
||||
|
||||
# Create the poll archetype
|
||||
register_archetype('poll', POLL_OPTIONS)
|
||||
|
||||
# Callbacks
|
||||
listen_for(:before_create_post)
|
||||
end
|
||||
|
||||
# Callbacks below
|
||||
def before_create_post(post)
|
||||
return unless post.archetype == 'poll'
|
||||
if post.post_number == 1
|
||||
post.sort_order = 1
|
||||
else
|
||||
post.sort_order = DiscoursePoll::Plugin::MAX_SORT_ORDER
|
||||
end
|
||||
end
|
||||
|
||||
module TopicViewSerializerMixin
|
||||
|
||||
def self.included(base)
|
||||
base.attributes :private_poll, :single_vote
|
||||
end
|
||||
|
||||
def private_poll
|
||||
object.topic.has_meta_data_boolean?(:private_poll)
|
||||
end
|
||||
|
||||
def single_vote
|
||||
object.topic.has_meta_data_boolean?(:single_vote)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
3
vendor/gems/discourse_poll/lib/discourse_poll/version.rb
vendored
Normal file
3
vendor/gems/discourse_poll/lib/discourse_poll/version.rb
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module DiscoursePoll
|
||||
VERSION = "0.0.1"
|
||||
end
|
Reference in New Issue
Block a user