Sha256: 74e06aba967ceb382a831034a1a7a54c02923e3d71fb5d45298ad61e51329d60

Contents?: true

Size: 834 Bytes

Versions: 11

Compression:

Stored size: 834 Bytes

Contents

require "nkf"

module SmallCage

  # In _dir.smc or other *.smc, set charset like this:
  # 
  #   charset: Shift_JIS
  #   
  class NkfFilter

    def initialize(opts)
    end

    def after_rendering_filter(obj, str)
      charset = ""
      if obj["charset"]
        charset = obj["charset"]
      else
        obj["dirs"].reverse.each do |dir|
          if dir["charset"]
            charset = dir["charset"]
            break
          end
        end
      end

      opt = ""
      if charset =~ /^euc-jp$/i
        opt = "-Wem0"
      elsif charset =~ /^iso-2022-jp$/i
        opt = "-Wjm0"
      elsif charset =~ /^shift_jis$/i
        opt = "-Wsm0"
      else
        STDERR.puts "Unknown charset: #{charset}" unless charset.empty? 
        return str
      end      
      
      return NKF.nkf(opt, str)
    end

  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
bluemark-smallcage-0.1.5 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.2.4 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.2.3 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.2.2 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.2.1 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.2.0 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.1.9 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.1.8 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.1.7 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.1.6 project/nkf/_smc/filters/nkf_filter.rb
smallcage-0.1.5 project/nkf/_smc/filters/nkf_filter.rb