[Groonga-commit] ranguba/chupa-text at f467dad [master] Support configuring content-type in configuration file

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jan 3 18:07:21 JST 2014


Kouhei Sutou	2014-01-03 18:07:21 +0900 (Fri, 03 Jan 2014)

  New Revision: f467dade01e4e013f576f1a43334c5b5d43c88d3
  https://github.com/ranguba/chupa-text/commit/f467dade01e4e013f576f1a43334c5b5d43c88d3

  Message:
    Support configuring content-type in configuration file

  Added files:
    data/content-types.conf
  Modified files:
    lib/chupa-text/configuration-loader.rb
    lib/chupa-text/configuration.rb

  Added: data/content-types.conf (+8 -0) 100644
===================================================================
--- /dev/null
+++ data/content-types.conf    2014-01-03 18:07:21 +0900 (08109bb)
@@ -0,0 +1,8 @@
+# -*- ruby -*-
+
+content_type["txt"] = "text/plain"
+
+content_type["gz"]  = "application/x-gzip"
+content_type["tgz"] = "application/x-gtar-compressed"
+
+content_type["tar"] = "application/x-tar"

  Modified: lib/chupa-text/configuration-loader.rb (+12 -0)
===================================================================
--- lib/chupa-text/configuration-loader.rb    2014-01-03 18:06:19 +0900 (c6e79e6)
+++ lib/chupa-text/configuration-loader.rb    2014-01-03 18:07:21 +0900 (0d09a67)
@@ -19,9 +19,11 @@ require "chupa-text/configuration"
 module ChupaText
   class ConfigurationLoader
     attr_reader :decomposer
+    attr_reader :content_type
     def initialize(configuration)
       @configuration = configuration
       @decomposer = DecomposerLoader.new(@configuration.decomposer)
+      @content_type = ContentTypeLoader.new(@configuration.content_type_registry)
       @load_paths = []
       data_dir = File.join(File.dirname(__FILE__), "..", "..", "data")
       @load_paths << File.expand_path(data_dir)
@@ -79,5 +81,15 @@ module ChupaText
         end
       end
     end
+
+    class ContentTypeLoader
+      def initialize(registry)
+        @registry = registry
+      end
+
+      def []=(extension, content_type)
+        @registry.register(extension, content_type)
+      end
+    end
   end
 end

  Modified: lib/chupa-text/configuration.rb (+2 -0)
===================================================================
--- lib/chupa-text/configuration.rb    2014-01-03 18:06:19 +0900 (7fd1d5e)
+++ lib/chupa-text/configuration.rb    2014-01-03 18:07:21 +0900 (c24deb9)
@@ -17,8 +17,10 @@
 module ChupaText
   class Configuration
     attr_reader :decomposer
+    attr_accessor :content_type_registry
     def initialize
       @decomposer = DecomposerConfiguration.new
+      @content_type_registry = ContentType.registry
     end
 
     class DecomposerConfiguration
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index