Class: Optimacms::CssFile

Inherits:
Object
  • Object
show all
Defined in:
app/models/optimacms/css_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#basepathObject

Returns the value of attribute basepath.



3
4
5
# File 'app/models/optimacms/css_file.rb', line 3

def basepath
  @basepath
end

#contentObject

content



78
79
80
# File 'app/models/optimacms/css_file.rb', line 78

def content
  @content
end

#is_folderObject

Returns the value of attribute is_folder.



3
4
5
# File 'app/models/optimacms/css_file.rb', line 3

def is_folder
  @is_folder
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/models/optimacms/css_file.rb', line 3

def name
  @name
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'app/models/optimacms/css_file.rb', line 3

def path
  @path
end

Class Method Details

.dir_baseObject



40
41
42
# File 'app/models/optimacms/css_file.rb', line 40

def self.dir_base
  "app/assets/stylesheets"
end

.get_allObject



32
33
34
35
# File 'app/models/optimacms/css_file.rb', line 32

def self.get_all

  get_list
end

.get_listObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/optimacms/css_file.rb', line 44

def self.get_list
  res = []

  #
  #Dir["#{dir_base}/**"].each do |f|
  #Dir.glob(File.join(dir_base, "**", "*#{File::Separator}")).each do |f|
  Dir.glob(File.join(dir_base, "**", "*")).each do |f|
    next if File.directory?(f)

    r = CssFile.new
    r.init_from_path(f)

    res << r
  end


  #files = files.sort_by{ |x| File.mtime(x) }.reverse

  res
end

Instance Method Details

#init_from_path(f) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/optimacms/css_file.rb', line 5

def init_from_path(f)
  if f =~ /^#{CssFile::dir_base}/
    # it is full path
    self.basepath = f.gsub /#{CssFile::dir_base}\/?/, ''
    self.path = f
  else
    # it is short path
    self.basepath = f
    self.path = "#{CssFile::dir_base}/#{f}"
  end


  #
  if File.file?(f)
    self.is_folder = false
  elsif File.directory?(f)
    self.is_folder = true
  end

end

#saveObject



70
71
72
73
74
# File 'app/models/optimacms/css_file.rb', line 70

def save
  save_content

  true
end

#save_contentObject



89
90
91
92
93
# File 'app/models/optimacms/css_file.rb', line 89

def save_content
  File.open(self.path, "w+") do |f|
    f.write(@content)
  end
end

#to_paramObject



27
28
29
# File 'app/models/optimacms/css_file.rb', line 27

def to_param
  basepath
end

#update_attributes(p) ⇒ Object



66
67
68
# File 'app/models/optimacms/css_file.rb', line 66

def update_attributes(p)
  self.content = p[:content]
end