Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 2644 Bytes
1 | class Resource < ActiveRecord::Base |
2 | validates_uniqueness_of :filename |
3 | after_destroy :delete_filename_on_disk |
4 | before_validation_on_create :uniq_filename_on_disk |
5 | belongs_to :article |
6 | |
7 | #Reads YAML file from config dir (iTunes.yml) for easy updating |
8 | def get_itunes_categories |
9 | itunes_categories_raw = YAML::load( File.open( "#{RAILS_ROOT}/config/iTunes.yml" ) ) |
10 | itunes_categories = [] |
11 | itunes_categories_raw.keys.sort.each do |cat| |
12 | itunes_categories.push cat => itunes_categories_raw[cat] |
13 | end |
14 | return itunes_categories |
15 | end |
16 | |
17 | def validate_on_update |
18 | if itunes_explicit? |
19 | errors.add_to_base("You must check the box to activate metadata.") unless itunes_metadata? |
20 | errors.add_to_base("You must specify an author.") if itunes_author.blank? |
21 | errors.add_to_base("You must specify an subtitle.") if itunes_subtitle.blank? |
22 | errors.add_to_base("You must specify a summary.") if itunes_summary.blank? |
23 | errors.add_to_base("You must specify keywords.") if itunes_keywords.blank? |
24 | if !itunes_duration.blank? |
25 | errors.add_to_base("You must specify duration in a HH:MM:SS format.") unless itunes_duration =~ /^(\d{0,2}:)?\d{1,2}:?\d{2}$/ |
26 | end |
27 | if !itunes_category.nil? |
28 | errors.add_to_base("You can only specify one parent category, but you can choose multiple sub categories.") if itunes_category.length > 1 |
29 | end |
30 | end |
31 | end |
32 | def fullpath(file = nil) |
33 | "#{RAILS_ROOT}/public/files/#{file.nil? ? filename : file}" |
34 | end |
35 | |
36 | def write_to_disk(up) |
37 | begin |
38 | # create the public/files dir if it doesn't exist |
39 | FileUtils.mkdir(fullpath('')) unless File.directory?(fullpath('')) |
40 | if up.kind_of?(Tempfile) and !up.local_path.nil? and File.exist?(up.local_path) |
41 | File.chmod(0600, up.local_path) |
42 | FileUtils.copy(up.local_path, fullpath) |
43 | else |
44 | bytes = up |
45 | if up.kind_of?(StringIO) |
46 | up.rewind |
47 | bytes = up.read |
48 | end |
49 | File.open(fullpath, "wb") { |f| f.write(bytes) } |
50 | end |
51 | File.chmod(0644, fullpath) |
52 | self.size = File.stat(fullpath).size rescue 0 |
53 | update |
54 | self |
55 | rescue |
56 | raise |
57 | end |
58 | end |
59 | |
60 | |
61 | protected |
62 | def uniq_filename_on_disk |
63 | i = 0 |
64 | raise if filename.empty? |
65 | tmpfile = File.basename(filename.gsub(/\\/, '/')).gsub(/[^\w\.\-]/,'_') |
66 | filename = tmpfile |
67 | while File.exists?(fullpath(tmpfile)) |
68 | i += 1 |
69 | tmpfile = filename.sub(/^(.*?)(\.[^\.]+)?$/, '\1'+"#{i}"+'\2') |
70 | end |
71 | self.filename = tmpfile |
72 | end |
73 | def delete_filename_on_disk |
74 | File.unlink(fullpath(filename)) if File.exist?(fullpath(filename)) |
75 | end |
76 | end |