asip-meteor 0.9.2.8 → 0.9.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/meteor.rb +93 -51
  2. metadata +2 -2
data/lib/meteor.rb CHANGED
@@ -18,12 +18,12 @@
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #
20
20
  # @author Yasumasa Ashida
21
- # @version 0.9.2.8
21
+ # @version 0.9.2.9
22
22
  #
23
23
 
24
24
  module Meteor
25
25
 
26
- VERSION = "0.9.2.8"
26
+ VERSION = "0.9.2.9"
27
27
 
28
28
  RUBY_VERSION_1_9_0 = '1.9.0'
29
29
 
@@ -575,111 +575,153 @@ module Meteor
575
575
  #
576
576
  class ParserFactory
577
577
 
578
+ attr_accessor :base_dir
579
+
580
+
578
581
  #
579
- # パーサファクトリを生成する
580
- #
581
- # @param [Array] args 引数配列
582
- # @return [Meteor::ParserFactory] パーサファクトリ
582
+ # イニシャライザ
583
+ # @params [Array] args 引数配列
583
584
  #
584
- def self.build(*args)
585
+ def initialize(*args)
585
586
  case args.length
586
- when THREE
587
- build_3(args[0],args[1],args[2])
588
- when TWO
589
- build_2(args[0],args[1])
587
+ when 0 then
588
+ initialize_0
589
+ when 1 then
590
+ initialize_1(args[0])
590
591
  else
591
592
  raise ArgumentError
592
593
  end
593
594
  end
594
595
 
595
596
  #
596
- # パーサファクトリを生成する
597
+ # イニシャライザ
598
+ #
599
+ def initialize_0
600
+ @cache = Hash.new
601
+ @base_dir = "."
602
+ end
603
+ private :initialize_0
604
+
605
+ #
606
+ # イニシャライザ
607
+ # @param [String] bs_dir 基準ディレクトリ
608
+ #
609
+ def initialize_1(bs_dir)
610
+ @cache = Hash.new
611
+ @base_dir = bs_dir
612
+ end
613
+ private :initialize_1
614
+
615
+ #
616
+ # パーサをセットする
617
+ #
618
+ #
619
+ def parser(*args)
620
+ case args.length
621
+ when 1 then
622
+ parser_1(args[0])
623
+ when 3 then
624
+ parser_3(args[0],args[1],args[2])
625
+ end
626
+ end
627
+
628
+ def parser_1(name)
629
+ @pif = @cache[name]
630
+
631
+ if @pif.instance_of?(Meteor::Core::Html::ParserImpl) then
632
+ Meteor::Core::Html::ParserImpl.new(@pif)
633
+ elsif @pif.instance_of?(Meteor::Core::Xhtml::ParserImpl) then
634
+ Meteor::Core::Xhtml::ParserImpl.new(@pif)
635
+ elsif @pif.instance_of?(Meteor::Core::Xml::ParserImpl) then
636
+ Meteor::Core::Xml::ParserImpl.new(@pif)
637
+ end
638
+ end
639
+ private :parser_1
640
+
641
+ #
642
+ # パーサをセットする
597
643
  #
598
644
  # @param [Fixnum] type パーサのタイプ
599
- # @param [String] path ファイルパス
645
+ # @param [String] relative_path 相対ファイルパス
600
646
  # @param [String] encoding エンコーディング
601
647
  # @return [Meteor::ParserFactory] パーサファクトリ
602
648
  #
603
- def self.build_3(type,path,encoding)
604
- psf = ParserFactory.new
649
+ def parser_3(type,relative_path,encoding)
650
+
651
+ paths = File.split(relative_path)
652
+
653
+ if '.'.eql?(paths[0]) then
654
+ relative_url = File.basename(paths[1],'.*')
655
+ else
656
+ relative_url = [paths[0],File.basename(paths[1],'.*')].join("/")
657
+ end
605
658
 
606
659
  case type
607
660
  when Parser::HTML then
608
661
  html = Meteor::Core::Html::ParserImpl.new()
609
- html.read(path, encoding)
662
+ html.read(File.expand_path(relative_path,@base_dir), encoding)
610
663
  html.doc_type = Parser::HTML
611
- psf.parser = html
664
+ @cache[relative_url] = html
612
665
  when Parser::XHTML then
613
666
  xhtml = Meteor::Core::Xhtml::ParserImpl.new()
614
- xhtml.read(path, encoding)
667
+ xhtml.read(File.expand_path(relative_path,@base_dir), encoding)
615
668
  xhtml.doc_type = Parser::XHTML
616
- psf.parser = xhtml
669
+ @cache[relative_url] = xhtml
617
670
  when Parser::XML then
618
671
  xml = Meteor::Core::Xml::ParserImpl.new()
619
- xml.read(path, encoding)
672
+ xml.read(File.expand_path(relative_path,@base_dir), encoding)
620
673
  xml.doc_type = Parser::XML
621
- psf.parser = xml
674
+ @cache[relative_url] = xml
622
675
  end
623
-
624
- psf
676
+
625
677
  end
626
- #protected :build_3
678
+ private :parser_3
627
679
 
628
680
  #
629
- # パーサファクトリを生成する
630
- #
681
+ # パーサをセットする
682
+ #
631
683
  # @param [Fixnum] type パーサのタイプ
684
+ # @param [String] relative_url 相対URL
632
685
  # @param [String] document ドキュメント
633
686
  # @return [Meteor::ParserFactory] パーサファクトリ
634
687
  #
635
- def self.build_2(type,document)
636
- psf = ParserFactory.new
637
-
688
+ def parser_str(type,relative_url,document)
638
689
  case type
639
690
  when Parser::HTML then
640
691
  html = Meteor::Core::Html::ParserImpl.new()
641
692
  html.parse(document)
642
693
  html.doc_type = Parser::HTML
643
- psf.parser = html
694
+ @cache[relative_url] = html
644
695
  when Parser::XHTML then
645
696
  xhtml = Meteor::Core::Xhtml::ParserImpl.new()
646
697
  xhtml.parse(document)
647
698
  xhtml.doc_type = Parser::XHTML
648
- psf.parser = xhtml
699
+ @cache[relative_url] = xhtml
649
700
  when Parser::XML then
650
701
  xml = Meteor::Core::Xml::ParserImpl.new()
651
702
  xml.parse(document)
652
703
  xml.doc_type = Parser::XML
653
- psf.parser = xml
654
- end
655
-
656
- psf
657
- end
658
- #protected :build_2
704
+ @cache[relative_url] = xml
705
+ end
706
+ end
659
707
 
660
708
  #
661
709
  # パーサをセットする
662
- #
663
- # @param [Meteor::Parser] パーサ
710
+ # @param [String] name 名前
711
+ # @param [Meteor::Parser] pif パーサ
664
712
  #
665
- def parser=(pif)
666
- @pif = pif
713
+ def []=(name,pif)
714
+ @cache[path] = pif
667
715
  end
668
716
 
669
717
  #
670
718
  # パーサを取得する
671
- #
719
+ #
720
+ #
672
721
  # @return [Meteor::Parser] パーサ
673
722
  #
674
- def parser
675
-
676
- if @pif.instance_of?(Meteor::Core::Html::ParserImpl) then
677
- Meteor::Core::Html::ParserImpl.new(@pif)
678
- elsif @pif.instance_of?(Meteor::Core::Xhtml::ParserImpl) then
679
- Meteor::Core::Xhtml::ParserImpl.new(@pif)
680
- elsif @pif.instance_of?(Meteor::Core::Xml::ParserImpl) then
681
- Meteor::Core::Xml::ParserImpl.new(@pif)
682
- end
723
+ def [](name)
724
+ self.parser(name)
683
725
  end
684
726
 
685
727
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asip-meteor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2.8
4
+ version: 0.9.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - asip
@@ -9,7 +9,7 @@ autorequire: meteor
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-10 00:00:00 -07:00
12
+ date: 2009-07-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15