2011-02-01 09:57:29 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
module ContextModulesHelper
|
2013-12-14 08:27:05 +08:00
|
|
|
def cache_if_module(context_module, editable, draft_state, &block)
|
2013-03-09 06:46:28 +08:00
|
|
|
if context_module
|
2014-06-11 04:08:36 +08:00
|
|
|
cache(['context_module_render_11_', context_module.cache_key, editable, draft_state].join('/'), nil, &block)
|
2013-03-09 06:46:28 +08:00
|
|
|
else
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2013-10-03 06:37:45 +08:00
|
|
|
|
|
|
|
def module_item_published?(item)
|
|
|
|
# If I publish an attachment, but its folder is hidden, the file is still
|
|
|
|
# hidden, now what? WHAT DO WE DO?
|
|
|
|
item && ((item.content && item.content.respond_to?(:published?)) ? item.content : item).published?
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_item_publishable_id(item)
|
|
|
|
if item.nil?
|
|
|
|
''
|
|
|
|
elsif (item.content_type_class == 'wiki_page')
|
|
|
|
item.content.url
|
|
|
|
else
|
|
|
|
(item.content && item.content.respond_to?(:published?) ? item.content.id : item.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_item_publishable?(item)
|
2014-01-04 07:03:51 +08:00
|
|
|
true
|
2013-10-03 06:37:45 +08:00
|
|
|
end
|
|
|
|
|
2014-01-04 07:03:51 +08:00
|
|
|
def module_item_unpublishable?(item)
|
|
|
|
return true if item.nil? || !item.content || !item.content.respond_to?(:can_unpublish?)
|
|
|
|
item.content.can_unpublish?
|
|
|
|
end
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|