Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Make Section a separate entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
threedaymonk committed Apr 24, 2012
1 parent aba059d commit 1e07b7a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions app/models/section.rb
@@ -0,0 +1,35 @@
class Section

def initialize(top_level, name)
@top_level = top_level
@name = name
end

def slug
[@top_level, @name].join(":")
end

def to_s
[@top_level, @name].join(" > ")
end

class << self
def all
@sections ||= load_sections
end

private
def load_sections
top_level = nil
File.open(File.expand_path("../sections.txt", __FILE__)).inject([]) { |sections, line|
if line =~ /^ /
raise "Bad section.txt, must start with a section (no spaces at start of first line)" if top_level.nil?
sections << new(top_level, line.strip)
else
top_level = line.strip
sections
end
}
end
end
end
2 changes: 1 addition & 1 deletion app/views/artefacts/_form.html.erb
Expand Up @@ -29,7 +29,7 @@
</span>
<% end %>
</li>
<%= f.input :section, :as => :select, :collection => Artefact.sections.map {|s| [s.gsub(':', ' > '), s] } %>
<%= f.input :section, :as => :select, :collection => Section.all.map { |s| [s.to_s, s.slug] } %>
<% end %>
<%= f.inputs "Related items", :class => "related" do %>
<%= f.semantic_fields_for :related_items, related_items_for(artefact) do |related_item| %>
Expand Down

0 comments on commit 1e07b7a

Please sign in to comment.