Sha256: 41546e4f1231eddb3532a05c7d5231612b3020d599e6fb5aa02672d79cd3d96f

Contents?: true

Size: 1.32 KB

Versions: 33

Compression:

Stored size: 1.32 KB

Contents

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

      def initialize
        reload!
      end

      # Implement generic Theme interface
      attr_reader :templates, :assets

      def public?
        false # just for tests
      end

      def path
        nil
      end

      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

33 entries across 33 versions & 1 rubygems

Version Path
bootic_cli-1.2.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-1.1.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-1.0.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.9.6 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.9.5 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.9.4 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.9.3 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.9.2 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.9.1 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.9.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.8.2 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.8.1 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.8.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.7.3 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.7.2 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.7.1 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.7.0 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.6.7 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.6.6 lib/bootic_cli/themes/mem_theme.rb
bootic_cli-0.6.5 lib/bootic_cli/themes/mem_theme.rb