Sha256: 8004fb237aa984b97cae9c3bd6b3fbc6ca89769b4d836b0203a1f23e16ca5e54

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

module BooticCli
  module Themes
    class MemTheme
      Template = Struct.new(:file_name, :body, :updated_on)
      ThemeAsset = Struct.new(:file_name, :file, :updated_on)

      def initialize
        reload!
      end

      # Implement generic Theme interface
      attr_reader :templates, :assets

      def reload!
        @templates = []
        @assets = []
      end

      def add_template(file_name, body, mtime: Time.now)
        tpl = Template.new(file_name, body, mtime)
        if idx = templates.index{|t| t.file_name == file_name }
          templates[idx] = tpl
        else
          templates << tpl
        end
      end

      def remove_template(file_name)
        if idx = templates.index{|t| t.file_name == file_name }
          templates.delete_at idx
        end
      end

      def add_asset(file_name, file, mtime: Time.now)
        asset = ThemeAsset.new(file_name, file, mtime)
        if idx = assets.index{|t| t.file_name == file_name }
          assets[idx] = asset
        else
          assets << asset
        end
      end

      def remove_asset(file_name)
        if idx = assets.index{|t| t.file_name == file_name }
          assets.delete_at idx
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bootic_cli-0.3.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.2.1 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.2.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.2.0.pre4 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.2.0.pre3 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.2.0.pre2 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.2.0.pre1 lib/bootic_cli/themes/mem_theme.rb