Skip to content

Commit

Permalink
Merge branch 'chiliproject'
Browse files Browse the repository at this point in the history
  • Loading branch information
stgeneral committed Jan 9, 2013
2 parents dfa7c7a + 77cf667 commit fbab503
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/views/settings/_progressive_projects_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<div class="tabular settings">
<% if Rails::VERSION::MAJOR >= 3 %>
<p>
<%= setting_label(:show_project_menu) %>
<%= check_box_tag('settings[show_project_menu]', true, @settings['show_project_menu']) %>
</p>
<% end %>
<p>
<%= setting_label(:show_project_description) %>
<%= check_box_tag('settings[show_project_description]', true, @settings['show_project_description']) %>
Expand Down
14 changes: 11 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
}, :partial => 'settings/progressive_projects_list'
end

require 'progressive_projects_list_listener'
require 'progressive_projects_list'
ProjectsHelper.send(:include, ProgressiveProjectsList)
if Rails::VERSION::MAJOR >= 3
require 'progressive_projects_list_listener'
require 'progressive_projects_list'
else
# Rails 2.x (ChiliProject) compatibility
require 'dispatcher'
Dispatcher.to_prepare :progressive_projects_list do
require_dependency 'progressive_projects_list'
require_dependency 'progressive/application_helper_patch'
end
end
44 changes: 44 additions & 0 deletions lib/progressive/application_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Progressive::ApplicationHelperPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
end

module InstanceMethods
# Renders a tree of projects as a nested set of unordered lists
# The given collection may be a subset of the whole project tree
# (eg. some intermediate nodes are private and can not be seen)
def render_project_nested_lists(projects)
s = ''
if projects.any?
ancestors = []
original_project = @project
projects.sort_by(&:lft).each do |project|
# set the project environment to please macros.
@project = project
if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
else
ancestors.pop
s << "</li>"
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
ancestors.pop
s << "</ul></li>\n"
end
end
classes = (ancestors.empty? ? 'root' : 'child')
s << "<li class='#{classes}'><div class='#{classes}'>"
s << h(block_given? ? yield(project) : project.name)
s << "</div>\n"
ancestors << project
end
s << ("</li></ul>\n" * ancestors.size)
@project = original_project
end
s.html_safe
end
end
end

unless ApplicationHelper.included_modules.include? Progressive::ApplicationHelperPatch
ApplicationHelper.send(:include, Progressive::ApplicationHelperPatch)
end
4 changes: 4 additions & 0 deletions lib/progressive_projects_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ def render_project_menu(project)
end
end
end

unless ProjectsHelper.included_modules.include? ProgressiveProjectsList
ProjectsHelper.send(:include, ProgressiveProjectsList)
end

0 comments on commit fbab503

Please sign in to comment.