Sha256: 1cb77810922dd55636692f7ccdfb39e1bdf730367660b916437e831364f6189e

Contents?: true

Size: 1.54 KB

Versions: 25

Compression:

Stored size: 1.54 KB

Contents

module Optimacms
  class CssFile
    attr_accessor :name, :basepath, :path, :is_folder, :content

    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

    ###
    def to_param
      basepath
    end

    ###
    def self.get_all

      get_list
    end


    ###

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

    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

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

    def save
      save_content

      true
    end

    ### content

    def content
      return @content unless @content.nil?

      #
      return '' if !File.exists? self.path
      @content = File.read(self.path)

      @content
    end


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

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
optimacms-0.1.61 app/models/optimacms/css_file.rb
optimacms-0.4.3 app/models/optimacms/css_file.rb
optimacms-0.4.2 app/models/optimacms/css_file.rb
optimacms-0.3.35 app/models/optimacms/css_file.rb
optimacms-0.3.34 app/models/optimacms/css_file.rb
optimacms-0.3.30 app/models/optimacms/css_file.rb
optimacms-0.3.29 app/models/optimacms/css_file.rb
optimacms-0.3.23 app/models/optimacms/css_file.rb
optimacms-0.3.15 app/models/optimacms/css_file.rb
optimacms-0.3.12 app/models/optimacms/css_file.rb
optimacms-0.3.11 app/models/optimacms/css_file.rb
optimacms-0.3.9 app/models/optimacms/css_file.rb
optimacms-0.3.8 app/models/optimacms/css_file.rb
optimacms-0.3.7 app/models/optimacms/css_file.rb
optimacms-0.3.6 app/models/optimacms/css_file.rb
optimacms-0.3.5 app/models/optimacms/css_file.rb
optimacms-0.2.26 app/models/optimacms/css_file.rb
optimacms-0.2.25 app/models/optimacms/css_file.rb
optimacms-0.2.24 app/models/optimacms/css_file.rb
optimacms-0.3.4 app/models/optimacms/css_file.rb