meteor 0.9.7.4 → 0.9.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/meteor.rb +556 -110
- metadata +3 -3
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.7.
|
21
|
+
# @version 0.9.7.5
|
22
22
|
#
|
23
23
|
|
24
24
|
module Meteor
|
25
25
|
|
26
|
-
VERSION = "0.9.7.
|
26
|
+
VERSION = "0.9.7.5"
|
27
27
|
|
28
28
|
RUBY_VERSION_1_9_0 = '1.9.0'
|
29
29
|
|
@@ -303,7 +303,7 @@ module Meteor
|
|
303
303
|
end
|
304
304
|
end
|
305
305
|
|
306
|
-
alias child element
|
306
|
+
alias :child :element
|
307
307
|
|
308
308
|
#
|
309
309
|
# get child element using selector like css3(CSS3のようにセレクタを用いて子要素を取得する)
|
@@ -336,8 +336,9 @@ module Meteor
|
|
336
336
|
#
|
337
337
|
# @overload attr(attr)
|
338
338
|
# set attribute of element (要素の属性をセットする)
|
339
|
-
# @param [Hash] attr attribute
|
339
|
+
# @param [Hash] attr attribute (属性)
|
340
340
|
# @return [Meteor::Element] element (要素)
|
341
|
+
# @deprecated
|
341
342
|
# @overload attr(attr_name,attr_value)
|
342
343
|
# set attribute of element (要素の属性をセットする)
|
343
344
|
# @param [String] attr_name attribute name (属性名)
|
@@ -352,11 +353,37 @@ module Meteor
|
|
352
353
|
@parser.attr(self, attrs,*args)
|
353
354
|
end
|
354
355
|
|
356
|
+
#
|
357
|
+
# set attribute of element (要素の属性をセットする)
|
358
|
+
# @param [Hash] attr attribute (属性)
|
359
|
+
# @return [Meteor::Element] element (要素)
|
360
|
+
#
|
361
|
+
def attr=(attr)
|
362
|
+
@parser.attr(self,attr)
|
363
|
+
end
|
364
|
+
|
365
|
+
#
|
366
|
+
# set attribute map (要素マップをセットする)
|
367
|
+
# @params [Hash] attr_map attributes (属性マップ)
|
368
|
+
# @return [Meteor::Element] element (要素)
|
369
|
+
def attrs=(attrs)
|
370
|
+
@parser.attrs(self,attrs)
|
371
|
+
end
|
372
|
+
|
373
|
+
#
|
374
|
+
# get attribute map (属性マップを取得する)
|
375
|
+
# @return [Hash] attribute map (属性マップ)
|
376
|
+
#
|
377
|
+
def attrs
|
378
|
+
@parser.attrs(self)
|
379
|
+
end
|
380
|
+
|
355
381
|
#
|
356
382
|
# @overload attr_map(attr_map)
|
357
383
|
# set attribute map (属性マップをセットする)
|
358
384
|
# @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
|
359
385
|
# @return [Meteor::Element] element (要素)
|
386
|
+
# @deprecated
|
360
387
|
# @overload attr_map()
|
361
388
|
# get attribute map (属性マップを取得する)
|
362
389
|
# @return [Meteor::AttributeMap] attribute map (属性マップ)
|
@@ -365,6 +392,15 @@ module Meteor
|
|
365
392
|
@parser.attr_map(self, *args)
|
366
393
|
end
|
367
394
|
|
395
|
+
#
|
396
|
+
# set attribute map (属性マップをセットする)
|
397
|
+
# @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
|
398
|
+
# @return [Meteor::Element] element (要素)
|
399
|
+
#
|
400
|
+
def attr_map=(attr_map)
|
401
|
+
@parser.attr_map(self,attr_map)
|
402
|
+
end
|
403
|
+
|
368
404
|
#
|
369
405
|
# @overload content(content,entity_ref=true)
|
370
406
|
# set content of element (要素の内容をセットする)
|
@@ -384,8 +420,8 @@ module Meteor
|
|
384
420
|
end
|
385
421
|
|
386
422
|
#
|
387
|
-
# set content of element (
|
388
|
-
# @param [String] value content (
|
423
|
+
# set content of element (要素の内容をセットする)
|
424
|
+
# @param [String] value content (要素の内容)
|
389
425
|
# @return [Meteor::Element] element (要素)
|
390
426
|
#
|
391
427
|
def content=(value)
|
@@ -403,7 +439,7 @@ module Meteor
|
|
403
439
|
end
|
404
440
|
|
405
441
|
#
|
406
|
-
# 属性の値を取得する
|
442
|
+
# get attribute value (属性の値を取得する)
|
407
443
|
# @param [String] name attribute name (属性の名前)
|
408
444
|
# @return [String] attribute value (属性の値)
|
409
445
|
#
|
@@ -471,7 +507,7 @@ module Meteor
|
|
471
507
|
attr_accessor :content_type #[String] content type (コンテントタイプ)
|
472
508
|
attr_accessor :kaigyo_code #[String] newline (改行コード)
|
473
509
|
attr_accessor :charset #[String] charset (文字コード)
|
474
|
-
attr_accessor :character_encoding #[String] character encoding (
|
510
|
+
attr_accessor :character_encoding #[String] character encoding (文字エンコーディング)
|
475
511
|
#attr_accessor :document #[String] document (ドキュメント)
|
476
512
|
end
|
477
513
|
|
@@ -506,6 +542,8 @@ module Meteor
|
|
506
542
|
@recordable = false
|
507
543
|
end
|
508
544
|
|
545
|
+
private :initialize_0
|
546
|
+
|
509
547
|
#
|
510
548
|
# initializer (イニシャライザ)
|
511
549
|
# @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
|
@@ -516,6 +554,8 @@ module Meteor
|
|
516
554
|
@recordable = attr_map.recordable
|
517
555
|
end
|
518
556
|
|
557
|
+
private :initialize_1
|
558
|
+
|
519
559
|
#
|
520
560
|
# set a couple of attribute name and attribute value (属性名と属性値を対としてセットする)
|
521
561
|
# @param [String] name attribute name (属性名)
|
@@ -630,6 +670,8 @@ module Meteor
|
|
630
670
|
@recordable = false
|
631
671
|
end
|
632
672
|
|
673
|
+
private :initialize_0
|
674
|
+
|
633
675
|
#
|
634
676
|
# initializer (イニシャライザ)
|
635
677
|
# @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
|
@@ -641,6 +683,8 @@ module Meteor
|
|
641
683
|
@recordable = attr_map.recordable
|
642
684
|
end
|
643
685
|
|
686
|
+
private :initialize_1
|
687
|
+
|
644
688
|
#
|
645
689
|
# set a couple of attribute name and attribute value (属性名と属性値を対としてセットする)
|
646
690
|
# @param [String] name attribute name (属性名)
|
@@ -721,17 +765,24 @@ module Meteor
|
|
721
765
|
SLASH = '/'
|
722
766
|
ENC_UTF8 = 'UTF-8'
|
723
767
|
|
768
|
+
attr_accessor :base_type #[FixNum] default type of parser (デフォルトのパーサ・タイプ)
|
724
769
|
attr_accessor :base_dir #[String] base directory (基準ディレクトリ)
|
725
|
-
attr_accessor :
|
770
|
+
attr_accessor :base_enc #[String] default character encoding (デフォルトエンコーディング)
|
771
|
+
|
772
|
+
alias :base_encoding :base_enc
|
726
773
|
|
727
774
|
#
|
728
775
|
# initializer (イニシャライザ)
|
729
776
|
# @overload initialize()
|
730
777
|
# @overload initialize(bs_dir)
|
731
778
|
# @param [String] bs_dir base directory (基準ディレクトリ)
|
732
|
-
# @overload initialize(bs_dir,
|
779
|
+
# @overload initialize(bs_dir,bs_enc)
|
780
|
+
# @param [String] bs_dir base directory (基準ディレクトリ)
|
781
|
+
# @param [String] bs_enc default character encoding (デフォルトエンコーディング)
|
782
|
+
# @overload initialize(bs_type,bs_dir,bs_enc)
|
783
|
+
# @param [FixNum] bs_type default type of parser (デフォルトのパーサ・タイプ)
|
733
784
|
# @param [String] bs_dir base directory (基準ディレクトリ)
|
734
|
-
# @param [String]
|
785
|
+
# @param [String] bs_enc default character encoding (デフォルト文字エンコーディング)
|
735
786
|
#
|
736
787
|
def initialize(*args)
|
737
788
|
case args.length
|
@@ -741,6 +792,8 @@ module Meteor
|
|
741
792
|
initialize_1(args[0])
|
742
793
|
when 2 then
|
743
794
|
initialize_2(args[0], args[1])
|
795
|
+
when 3 then
|
796
|
+
initialize_3(args[0],args[1],args[2])
|
744
797
|
else
|
745
798
|
raise ArgumentError
|
746
799
|
end
|
@@ -752,7 +805,7 @@ module Meteor
|
|
752
805
|
def initialize_0
|
753
806
|
@cache = Hash.new
|
754
807
|
@base_dir = CURRENT_DIR
|
755
|
-
@
|
808
|
+
@base_enc = ENC_UTF8
|
756
809
|
end
|
757
810
|
|
758
811
|
private :initialize_0
|
@@ -764,7 +817,7 @@ module Meteor
|
|
764
817
|
def initialize_1(bs_dir)
|
765
818
|
@cache = Hash.new
|
766
819
|
@base_dir = bs_dir
|
767
|
-
@
|
820
|
+
@base_enc = ENC_UTF8
|
768
821
|
end
|
769
822
|
|
770
823
|
private :initialize_1
|
@@ -772,51 +825,103 @@ module Meteor
|
|
772
825
|
#
|
773
826
|
# イニシャライザ
|
774
827
|
# @param [String] bs_dir base directory (基準ディレクトリ)
|
775
|
-
# @param [String]
|
828
|
+
# @param [String] bs_enc default character encoding (デフォルト文字エンコーディング)
|
776
829
|
#
|
777
|
-
def initialize_2(bs_dir,
|
830
|
+
def initialize_2(bs_dir, bs_enc)
|
778
831
|
@cache = Hash.new
|
779
832
|
@base_dir = bs_dir
|
780
|
-
@
|
833
|
+
@base_enc = bs_enc
|
781
834
|
end
|
782
835
|
|
783
|
-
private :
|
836
|
+
private :initialize_2
|
837
|
+
|
838
|
+
#
|
839
|
+
# イニシャライザ
|
840
|
+
# @paeam [FixNum] bs_type default type of parser (デフォルトのパーサ・タイプ)
|
841
|
+
# @param [String] bs_dir base directory (基準ディレクトリ)
|
842
|
+
# @param [String] bs_enc default character encoding (デフォルト文字エンコーディング)
|
843
|
+
#
|
844
|
+
def initialize_3(bs_type , bs_dir, bs_enc)
|
845
|
+
@cache = Hash.new
|
846
|
+
@base_type = bs_type
|
847
|
+
@base_dir = bs_dir
|
848
|
+
@base_enc = bs_enc
|
849
|
+
end
|
850
|
+
|
851
|
+
private :initialize_3
|
852
|
+
|
853
|
+
#
|
854
|
+
# set options (オプションをセットする)
|
855
|
+
# @param [Hash] opts option (オプション)
|
856
|
+
# @option opts [String] :base_dir base directory (基準ディレクトリ)
|
857
|
+
# @option opts [String] :base_enc default character encoding (デフォルト文字エンコーディング)
|
858
|
+
# @option opts [FixNum] :base_type default type of parser (デフォルトのパーサ・タイプ)
|
859
|
+
#
|
860
|
+
def options=(opts)
|
861
|
+
if opts.kind_of?(Hash)
|
862
|
+
if opts.include?(:base_dir)
|
863
|
+
@base_dir = opts[:base_dir]
|
864
|
+
end
|
865
|
+
if opts.include?(:base_enc)
|
866
|
+
@base_enc = opts[:base_enc]
|
867
|
+
end
|
868
|
+
if opts.include?(:base_type)
|
869
|
+
@base_type= opts[:base_type]
|
870
|
+
end
|
871
|
+
else
|
872
|
+
raise ArgumentError
|
873
|
+
end
|
874
|
+
end
|
784
875
|
|
785
876
|
#
|
786
|
-
#@overload
|
877
|
+
#@overload bind(relative_path,enc)
|
787
878
|
# generate parser (パーサを作成する)
|
788
|
-
# @param [Fixnum] type type of parser (パーサのタイプ)
|
789
879
|
# @param [String] relative_path relative file path (相対ファイルパス)
|
790
|
-
# @param [String]
|
880
|
+
# @param [String] enc character encoding (文字エンコーディング)
|
791
881
|
# @return [Meteor::Parser] parser (パーサ)
|
792
|
-
#@overload
|
882
|
+
#@overload bind(relative_path)
|
793
883
|
# generate parser (パーサを作成する)
|
794
|
-
# @param [Fixnum] type type of parser (パーサのタイプ)
|
795
884
|
# @param [String] relative_path relative file path (相対ファイルパス)
|
796
885
|
# @return [Meteor::Parser] parser (パーサ)
|
797
|
-
#@overload
|
798
|
-
#
|
799
|
-
# @param [
|
886
|
+
#@overload bind(type,relative_path,enc)
|
887
|
+
# generate parser (パーサを作成する)
|
888
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
889
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
890
|
+
# @param [String] enc character encoding (文字エンコーディング)
|
800
891
|
# @return [Meteor::Parser] parser (パーサ)
|
801
|
-
|
892
|
+
#@overload bind(type,relative_path)
|
893
|
+
# generate parser (パーサを作成する)
|
894
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
895
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
896
|
+
# @return [Meteor::Parser] parser (パーサ)
|
897
|
+
#
|
898
|
+
def bind(*args)
|
802
899
|
case args.length
|
803
900
|
when 1 then
|
804
|
-
|
901
|
+
bind_1(args[0])
|
805
902
|
when 2 then
|
806
|
-
|
903
|
+
if args[0].kind_of?(Fixnum)
|
904
|
+
bind_2_n(args[0], args[1])
|
905
|
+
elsif args[0].kind_of?(String)
|
906
|
+
bind_2_s(args[0], args[1])
|
907
|
+
else
|
908
|
+
raise ArgumentError
|
909
|
+
end
|
807
910
|
when 3 then
|
808
|
-
|
911
|
+
bind_3(args[0], args[1], args[2])
|
912
|
+
else
|
913
|
+
raise ArgumentError
|
809
914
|
end
|
810
915
|
end
|
811
916
|
|
812
917
|
#
|
813
918
|
# generate parser (パーサを作成する)
|
814
|
-
# @param [Fixnum] type type of parser (
|
919
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
815
920
|
# @param [String] relative_path relative file path (相対ファイルパス)
|
816
|
-
# @param [String]
|
921
|
+
# @param [String] enc character encoding (文字エンコーディング)
|
817
922
|
# @return [Meteor::Parser] parser(パーサ)
|
818
923
|
#
|
819
|
-
def
|
924
|
+
def bind_3(type, relative_path, enc)
|
820
925
|
|
821
926
|
paths = File.split(relative_path)
|
822
927
|
|
@@ -836,36 +941,36 @@ module Meteor
|
|
836
941
|
case type
|
837
942
|
when Parser::HTML then
|
838
943
|
html = Meteor::Ml::Html::ParserImpl.new()
|
839
|
-
html.read(File.expand_path(relative_path, @base_dir),
|
944
|
+
html.read(File.expand_path(relative_path, @base_dir), enc)
|
840
945
|
@cache[relative_url] = html
|
841
946
|
when Parser::XHTML then
|
842
947
|
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
843
|
-
xhtml.read(File.expand_path(relative_path, @base_dir),
|
948
|
+
xhtml.read(File.expand_path(relative_path, @base_dir), enc)
|
844
949
|
@cache[relative_url] = xhtml
|
845
950
|
when Parser::HTML5 then
|
846
951
|
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
847
|
-
html5.read(File.expand_path(relative_path, @base_dir),
|
952
|
+
html5.read(File.expand_path(relative_path, @base_dir), enc)
|
848
953
|
@cache[relative_url] = html5
|
849
954
|
when Parser::XHTML5 then
|
850
955
|
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
851
|
-
xhtml5.read(File.expand_path(relative_path, @base_dir),
|
956
|
+
xhtml5.read(File.expand_path(relative_path, @base_dir), enc)
|
852
957
|
@cache[relative_url] = xhtml5
|
853
958
|
when Parser::XML then
|
854
959
|
xml = Meteor::Ml::Xml::ParserImpl.new()
|
855
|
-
xml.read(File.expand_path(relative_path, @base_dir),
|
960
|
+
xml.read(File.expand_path(relative_path, @base_dir), enc)
|
856
961
|
@cache[relative_url] = xml
|
857
962
|
end
|
858
963
|
end
|
859
964
|
|
860
|
-
private :
|
965
|
+
private :bind_3
|
861
966
|
|
862
967
|
#
|
863
968
|
# generate parser (パーサを作成する)
|
864
|
-
# @param [Fixnum] type type of parser(
|
969
|
+
# @param [Fixnum] type type of parser(パーサ・タイプ)
|
865
970
|
# @param [String] relative_path relative file path (相対ファイルパス)
|
866
971
|
# @return [Meteor::Parser] parser (パーサ)
|
867
972
|
#
|
868
|
-
def
|
973
|
+
def bind_2_n(type, relative_path)
|
869
974
|
|
870
975
|
paths = File.split(relative_path)
|
871
976
|
|
@@ -885,29 +990,158 @@ module Meteor
|
|
885
990
|
case type
|
886
991
|
when Parser::HTML then
|
887
992
|
html = Meteor::Ml::Html::ParserImpl.new()
|
888
|
-
html.read(File.expand_path(relative_path, @base_dir), @
|
993
|
+
html.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
994
|
+
@cache[relative_url] = html
|
995
|
+
when Parser::XHTML then
|
996
|
+
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
997
|
+
xhtml.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
998
|
+
@cache[relative_url] = xhtml
|
999
|
+
when Parser::HTML5 then
|
1000
|
+
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
1001
|
+
html5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1002
|
+
@cache[relative_url] = html5
|
1003
|
+
when Parser::XHTML5 then
|
1004
|
+
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1005
|
+
xhtml5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1006
|
+
@cache[relative_url] = xhtml5
|
1007
|
+
when Parser::XML then
|
1008
|
+
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1009
|
+
xml.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1010
|
+
@cache[relative_url] = xml
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
private :bind_2_n
|
1016
|
+
|
1017
|
+
#
|
1018
|
+
# generate parser (パーサを作成する)
|
1019
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
1020
|
+
# @param [String] enc character encoding (文字エンコーディング)
|
1021
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1022
|
+
#
|
1023
|
+
def bind_2_s(relative_path,enc)
|
1024
|
+
|
1025
|
+
paths = File.split(relative_path)
|
1026
|
+
|
1027
|
+
if paths.length == 1 then
|
1028
|
+
relative_url = File.basename(paths[0], ABST_EXT_NAME)
|
1029
|
+
else
|
1030
|
+
if CURRENT_DIR.eql?(paths[0]) then
|
1031
|
+
paths.delete_at 0
|
1032
|
+
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
1033
|
+
relative_url = paths.join(SLASH)
|
1034
|
+
else
|
1035
|
+
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
1036
|
+
relative_url = paths.join(SLASH)
|
1037
|
+
end
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
case @base_type
|
1041
|
+
when Parser::HTML then
|
1042
|
+
html = Meteor::Ml::Html::ParserImpl.new()
|
1043
|
+
html.read(File.expand_path(relative_path, @base_dir), enc)
|
1044
|
+
@cache[relative_url] = html
|
1045
|
+
when Parser::XHTML then
|
1046
|
+
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
1047
|
+
xhtml.read(File.expand_path(relative_path, @base_dir), enc)
|
1048
|
+
@cache[relative_url] = xhtml
|
1049
|
+
when Parser::HTML5 then
|
1050
|
+
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
1051
|
+
html5.read(File.expand_path(relative_path, @base_dir), enc)
|
1052
|
+
@cache[relative_url] = html5
|
1053
|
+
when Parser::XHTML5 then
|
1054
|
+
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1055
|
+
xhtml5.read(File.expand_path(relative_path, @base_dir), enc)
|
1056
|
+
@cache[relative_url] = xhtml5
|
1057
|
+
when Parser::XML then
|
1058
|
+
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1059
|
+
xml.read(File.expand_path(relative_path, @base_dir), enc)
|
1060
|
+
@cache[relative_url] = xml
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
private :bind_2_s
|
1066
|
+
|
1067
|
+
#
|
1068
|
+
# generate parser (パーサを作成する)
|
1069
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
1070
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1071
|
+
#
|
1072
|
+
def bind_1(relative_path)
|
1073
|
+
|
1074
|
+
paths = File.split(relative_path)
|
1075
|
+
|
1076
|
+
if paths.length == 1 then
|
1077
|
+
relative_url = File.basename(paths[0], ABST_EXT_NAME)
|
1078
|
+
else
|
1079
|
+
if CURRENT_DIR.eql?(paths[0]) then
|
1080
|
+
paths.delete_at 0
|
1081
|
+
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
1082
|
+
relative_url = paths.join(SLASH)
|
1083
|
+
else
|
1084
|
+
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
1085
|
+
relative_url = paths.join(SLASH)
|
1086
|
+
end
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
case @base_type
|
1090
|
+
when Parser::HTML then
|
1091
|
+
html = Meteor::Ml::Html::ParserImpl.new()
|
1092
|
+
html.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
889
1093
|
@cache[relative_url] = html
|
890
1094
|
when Parser::XHTML then
|
891
1095
|
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
892
|
-
xhtml.read(File.expand_path(relative_path, @base_dir), @
|
1096
|
+
xhtml.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
893
1097
|
@cache[relative_url] = xhtml
|
894
1098
|
when Parser::HTML5 then
|
895
1099
|
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
896
|
-
html5.read(File.expand_path(relative_path, @base_dir), @
|
1100
|
+
html5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
897
1101
|
@cache[relative_url] = html5
|
898
1102
|
when Parser::XHTML5 then
|
899
1103
|
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
900
|
-
xhtml5.read(File.expand_path(relative_path, @base_dir), @
|
1104
|
+
xhtml5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
901
1105
|
@cache[relative_url] = xhtml5
|
902
1106
|
when Parser::XML then
|
903
1107
|
xml = Meteor::Ml::Xml::ParserImpl.new()
|
904
|
-
xml.read(File.expand_path(relative_path, @base_dir), @
|
1108
|
+
xml.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
905
1109
|
@cache[relative_url] = xml
|
1110
|
+
else
|
1111
|
+
raise ArgumentError
|
906
1112
|
end
|
907
1113
|
|
908
1114
|
end
|
909
1115
|
|
910
|
-
private :
|
1116
|
+
private :bind_1
|
1117
|
+
|
1118
|
+
#
|
1119
|
+
#@overload parser(key)
|
1120
|
+
# get parser (パーサを取得する)
|
1121
|
+
# @param [String] key identifier (キー)
|
1122
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1123
|
+
#@overload parser(type,relative_path,enc)
|
1124
|
+
# generate parser (パーサを作成する)
|
1125
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
1126
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
1127
|
+
# @param [String] enc character encoding (エンコーディング)
|
1128
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1129
|
+
# @deprecated
|
1130
|
+
#@overload parser(type,relative_path)
|
1131
|
+
# generate parser (パーサを作成する)
|
1132
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
1133
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
1134
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1135
|
+
# @deprecated
|
1136
|
+
def parser(*args)
|
1137
|
+
case args.length
|
1138
|
+
when 1 then
|
1139
|
+
parser_1(args[0])
|
1140
|
+
when 2,3 then
|
1141
|
+
bind(args)
|
1142
|
+
end
|
1143
|
+
#parser_1(key)
|
1144
|
+
end
|
911
1145
|
|
912
1146
|
#
|
913
1147
|
# get parser (パーサを取得する)
|
@@ -941,38 +1175,99 @@ module Meteor
|
|
941
1175
|
parser_1(key).root_element
|
942
1176
|
end
|
943
1177
|
|
1178
|
+
|
1179
|
+
# @overload bind_str(type, relative_url, doc)
|
1180
|
+
# generate parser (パーサを作成する)
|
1181
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
1182
|
+
# @param [String] relative_url relative URL (相対URL)
|
1183
|
+
# @param [String] doc document (ドキュメント)
|
1184
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1185
|
+
# @overload bind_str(relative_url, doc)
|
1186
|
+
# generate parser (パーサを作成する)
|
1187
|
+
# @param [String] relative_url relative URL (相対URL)
|
1188
|
+
# @param [String] doc document (ドキュメント)
|
1189
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1190
|
+
#
|
1191
|
+
def bind_str(*args)
|
1192
|
+
case args.length
|
1193
|
+
when 2 then
|
1194
|
+
bind_str_2(args[0],args[1])
|
1195
|
+
when 3 then
|
1196
|
+
bind_str_3(args[0],args[1],args[2])
|
1197
|
+
else
|
1198
|
+
raise ArgumentError
|
1199
|
+
end
|
1200
|
+
end
|
1201
|
+
|
944
1202
|
#
|
945
1203
|
# generate parser (パーサを作成する)
|
946
|
-
# @param [Fixnum] type type of parser (
|
1204
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
947
1205
|
# @param [String] relative_url relative URL (相対URL)
|
948
|
-
# @param [String]
|
1206
|
+
# @param [String] doc document (ドキュメント)
|
949
1207
|
# @return [Meteor::Parser] parser (パーサ)
|
950
1208
|
#
|
951
|
-
def
|
1209
|
+
def bind_str_3(type, relative_url, doc)
|
952
1210
|
case type
|
953
1211
|
when Parser::HTML then
|
954
1212
|
html = Meteor::Ml::Html::ParserImpl.new()
|
955
|
-
html.parse(
|
1213
|
+
html.parse(doc)
|
1214
|
+
@cache[relative_url] = html
|
1215
|
+
when Parser::XHTML then
|
1216
|
+
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
1217
|
+
xhtml.parse(doc)
|
1218
|
+
@cache[relative_url] = xhtml
|
1219
|
+
when Parser::HTML5 then
|
1220
|
+
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
1221
|
+
html5.parse(doc)
|
1222
|
+
@cache[relative_url] = html5
|
1223
|
+
when Parser::XHTML5 then
|
1224
|
+
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1225
|
+
xhtml5.parse(doc)
|
1226
|
+
@cache[relative_url] = xhtml5
|
1227
|
+
when Parser::XML then
|
1228
|
+
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1229
|
+
xml.parse(doc)
|
1230
|
+
@cache[relative_url] = xml
|
1231
|
+
end
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
private :bind_str_3
|
1235
|
+
|
1236
|
+
#
|
1237
|
+
# generate parser (パーサを作成する)
|
1238
|
+
# @param [String] relative_url relative URL (相対URL)
|
1239
|
+
# @param [String] doc document (ドキュメント)
|
1240
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1241
|
+
#
|
1242
|
+
def bind_str_2(relative_url, doc)
|
1243
|
+
case @base_type
|
1244
|
+
when Parser::HTML then
|
1245
|
+
html = Meteor::Ml::Html::ParserImpl.new()
|
1246
|
+
html.parse(doc)
|
956
1247
|
@cache[relative_url] = html
|
957
1248
|
when Parser::XHTML then
|
958
1249
|
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
959
|
-
xhtml.parse(
|
1250
|
+
xhtml.parse(doc)
|
960
1251
|
@cache[relative_url] = xhtml
|
961
1252
|
when Parser::HTML5 then
|
962
1253
|
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
963
|
-
html5.parse(
|
1254
|
+
html5.parse(doc)
|
964
1255
|
@cache[relative_url] = html5
|
965
1256
|
when Parser::XHTML5 then
|
966
1257
|
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
967
|
-
xhtml5.parse(
|
1258
|
+
xhtml5.parse(doc)
|
968
1259
|
@cache[relative_url] = xhtml5
|
969
1260
|
when Parser::XML then
|
970
1261
|
xml = Meteor::Ml::Xml::ParserImpl.new()
|
971
|
-
xml.parse(
|
1262
|
+
xml.parse(doc)
|
972
1263
|
@cache[relative_url] = xml
|
973
1264
|
end
|
974
1265
|
end
|
975
1266
|
|
1267
|
+
private :bind_str_2
|
1268
|
+
|
1269
|
+
alias :paraser_str :bind_str
|
1270
|
+
|
976
1271
|
#
|
977
1272
|
# set parser (パーサをセットする)
|
978
1273
|
# @param [String] key identifier (キー)
|
@@ -993,6 +1288,63 @@ module Meteor
|
|
993
1288
|
|
994
1289
|
end
|
995
1290
|
|
1291
|
+
#
|
1292
|
+
# Element Factory Class (要素ファクトリクラス)
|
1293
|
+
#
|
1294
|
+
class ElementFactory
|
1295
|
+
|
1296
|
+
@@pf = Meteor::ParserFactory.new
|
1297
|
+
|
1298
|
+
#
|
1299
|
+
# set options (オプションをセットする)
|
1300
|
+
# @param [Hash] opts option (オプション)
|
1301
|
+
# @option opts [String] :base_dir base directory (基準ディレクトリ)
|
1302
|
+
# @option opts [String] :base_enc default character encoding (デフォルト文字エンコーディング)
|
1303
|
+
# @option opts [FixNum] :base_type default type of parser (デフォルトのパーサ・タイプ)
|
1304
|
+
#
|
1305
|
+
def self.options=(opts)
|
1306
|
+
@@pf.options = opts
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
#
|
1310
|
+
#@overload bind(type,relative_path,enc)
|
1311
|
+
# generate parser (パーサを作成する)
|
1312
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
1313
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
1314
|
+
# @param [String] enc character encoding (エンコーディング)
|
1315
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1316
|
+
#@overload bind(type,relative_path)
|
1317
|
+
# generate parser (パーサを作成する)
|
1318
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
1319
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
1320
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1321
|
+
#
|
1322
|
+
def self.bind(*args)
|
1323
|
+
@@pf.bind(*args)
|
1324
|
+
end
|
1325
|
+
|
1326
|
+
#
|
1327
|
+
# generate parser (パーサを作成する)
|
1328
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
1329
|
+
# @param [String] relative_url relative URL (相対URL)
|
1330
|
+
# @param [String] document document (ドキュメント)
|
1331
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1332
|
+
#
|
1333
|
+
def self.bind_str(type, relative_url, document)
|
1334
|
+
@@pf.bind_str(type,relative_url,document)
|
1335
|
+
end
|
1336
|
+
|
1337
|
+
#
|
1338
|
+
# get root element (ルート要素を取得する)
|
1339
|
+
# @param [String] key identifier (キー)
|
1340
|
+
# @return [Meteor::RootElement] root element (ルート要素)
|
1341
|
+
#
|
1342
|
+
def self.element(key)
|
1343
|
+
@@pf.element(key)
|
1344
|
+
end
|
1345
|
+
|
1346
|
+
end
|
1347
|
+
|
996
1348
|
module Hook
|
997
1349
|
|
998
1350
|
#
|
@@ -1444,27 +1796,35 @@ module Meteor
|
|
1444
1796
|
#
|
1445
1797
|
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
1446
1798
|
# @param [String] file_path absolute path of input file (入力ファイルの絶対パス)
|
1447
|
-
# @param [String]
|
1799
|
+
# @param [String] enc character encoding of input file (入力ファイルの文字コード)
|
1448
1800
|
#
|
1449
|
-
def read(file_path,
|
1801
|
+
def read(file_path, enc)
|
1450
1802
|
|
1451
1803
|
#try {
|
1452
|
-
@character_encoding =
|
1804
|
+
@character_encoding = enc
|
1453
1805
|
#ファイルのオープン
|
1454
|
-
if ParserFactory::ENC_UTF8.eql?(
|
1455
|
-
#io = File.open(file_path,MODE_BF <<
|
1806
|
+
if ParserFactory::ENC_UTF8.eql?(enc) then
|
1807
|
+
#io = File.open(file_path,MODE_BF << enc)
|
1456
1808
|
io = File.open(file_path, MODE_UTF8)
|
1457
1809
|
else
|
1458
|
-
io = File.open(file_path, '' << MODE_BF <<
|
1810
|
+
io = File.open(file_path, '' << MODE_BF << enc << MODE_AF)
|
1459
1811
|
end
|
1460
1812
|
|
1461
1813
|
#読込及び格納
|
1462
|
-
|
1814
|
+
parse(io.read)
|
1463
1815
|
|
1464
1816
|
#ファイルのクローズ
|
1465
1817
|
io.close
|
1466
1818
|
end
|
1467
1819
|
|
1820
|
+
#
|
1821
|
+
# set document in parser (ドキュメントをパーサにセットする)
|
1822
|
+
# @param [String] document document (ドキュメント)
|
1823
|
+
#
|
1824
|
+
def parse(document)
|
1825
|
+
@root.document = document
|
1826
|
+
end
|
1827
|
+
|
1468
1828
|
#
|
1469
1829
|
# get element (要素を取得する)
|
1470
1830
|
# @overload element(tag)
|
@@ -1675,7 +2035,7 @@ module Meteor
|
|
1675
2035
|
|
1676
2036
|
def element_with_1(tag)
|
1677
2037
|
|
1678
|
-
@elm_ = Element.new(tag)
|
2038
|
+
@elm_ = Meteor::Element.new(tag)
|
1679
2039
|
#属性
|
1680
2040
|
@elm_.attributes = @res[2]
|
1681
2041
|
#内容
|
@@ -1701,7 +2061,7 @@ module Meteor
|
|
1701
2061
|
|
1702
2062
|
def element_without_1(tag)
|
1703
2063
|
#要素
|
1704
|
-
@elm_ = Element.new(tag)
|
2064
|
+
@elm_ = Meteor::Element.new(tag)
|
1705
2065
|
#属性
|
1706
2066
|
@elm_.attributes = @res[1]
|
1707
2067
|
#全体
|
@@ -1786,7 +2146,7 @@ module Meteor
|
|
1786
2146
|
case @res.captures.length
|
1787
2147
|
when FOUR
|
1788
2148
|
#要素
|
1789
|
-
@elm_ = Element.new(tag)
|
2149
|
+
@elm_ = Meteor::Element.new(tag)
|
1790
2150
|
#属性
|
1791
2151
|
@elm_.attributes = @res[1]
|
1792
2152
|
#内容
|
@@ -1807,7 +2167,7 @@ module Meteor
|
|
1807
2167
|
|
1808
2168
|
when FIVE
|
1809
2169
|
#要素
|
1810
|
-
@elm_ = Element.new(tag)
|
2170
|
+
@elm_ = Meteor::Element.new(tag)
|
1811
2171
|
#属性
|
1812
2172
|
@elm_.attributes = @res[2]
|
1813
2173
|
#内容
|
@@ -1828,7 +2188,7 @@ module Meteor
|
|
1828
2188
|
|
1829
2189
|
when THREE,SIX
|
1830
2190
|
#内容
|
1831
|
-
@elm_ = Element.new(tag)
|
2191
|
+
@elm_ = Meteor::Element.new(tag)
|
1832
2192
|
#属性
|
1833
2193
|
@elm_.attributes = @res[1].chop
|
1834
2194
|
#内容
|
@@ -1908,7 +2268,7 @@ module Meteor
|
|
1908
2268
|
def element_without_3_1(tag, closer)
|
1909
2269
|
|
1910
2270
|
#要素
|
1911
|
-
@elm_ = Element.new(tag)
|
2271
|
+
@elm_ = Meteor::Element.new(tag)
|
1912
2272
|
#属性
|
1913
2273
|
@elm_.attributes = @res[1]
|
1914
2274
|
#全体
|
@@ -2226,7 +2586,7 @@ module Meteor
|
|
2226
2586
|
case @res.captures.length
|
2227
2587
|
when FOUR
|
2228
2588
|
#要素
|
2229
|
-
@elm_ = Element.new(tag)
|
2589
|
+
@elm_ = Meteor::Element.new(tag)
|
2230
2590
|
#属性
|
2231
2591
|
@elm_.attributes = @res[1]
|
2232
2592
|
#内容
|
@@ -2249,7 +2609,7 @@ module Meteor
|
|
2249
2609
|
@elm_.parser = self
|
2250
2610
|
when FIVE
|
2251
2611
|
#要素
|
2252
|
-
@elm_ = Element.new(tag)
|
2612
|
+
@elm_ = Meteor::Element.new(tag)
|
2253
2613
|
#属性
|
2254
2614
|
@elm_.attributes = @res[2]
|
2255
2615
|
#内容
|
@@ -2273,7 +2633,7 @@ module Meteor
|
|
2273
2633
|
|
2274
2634
|
when THREE,SIX
|
2275
2635
|
#要素
|
2276
|
-
@elm_ = Element.new(tag)
|
2636
|
+
@elm_ = Meteor::Element.new(tag)
|
2277
2637
|
#属性
|
2278
2638
|
@elm_.attributes = @res[1].chop
|
2279
2639
|
#要素
|
@@ -2362,7 +2722,7 @@ module Meteor
|
|
2362
2722
|
def element_without_5_1(tag, closer)
|
2363
2723
|
|
2364
2724
|
#要素
|
2365
|
-
@elm_ = Element.new(tag)
|
2725
|
+
@elm_ = Meteor::Element.new(tag)
|
2366
2726
|
#属性
|
2367
2727
|
@elm_.attributes = @res[1]
|
2368
2728
|
#全体
|
@@ -2619,25 +2979,29 @@ module Meteor
|
|
2619
2979
|
# @param [String] attr_name attribute name (属性名)
|
2620
2980
|
# @return [String] attribute value (属性値)
|
2621
2981
|
#
|
2622
|
-
def attr(elm,
|
2623
|
-
if
|
2982
|
+
def attr(elm, attr,*args)
|
2983
|
+
if attr.kind_of?(String)
|
2624
2984
|
case args.length
|
2625
2985
|
when ZERO
|
2626
|
-
get_attr_value(elm,
|
2986
|
+
get_attr_value(elm, attr)
|
2627
2987
|
when ONE
|
2628
2988
|
elm.document_sync = true
|
2629
|
-
set_attribute_3(elm,
|
2989
|
+
set_attribute_3(elm, attr,args[0])
|
2630
2990
|
end
|
2631
2991
|
|
2632
|
-
elsif
|
2992
|
+
elsif attr.kind_of?(Hash) && attr.size == 1
|
2633
2993
|
elm.document_sync = true
|
2634
|
-
set_attribute_3(elm,
|
2994
|
+
set_attribute_3(elm, attr.keys[0], attr.values[0])
|
2995
|
+
#elsif attrs.kind_of?(Hash) && attrs.size >= 1
|
2996
|
+
# elm.document_sync = true
|
2997
|
+
# attrs.each{|name,value|
|
2998
|
+
# set_attribute_3(elm,name,value)
|
2999
|
+
# }
|
2635
3000
|
else
|
2636
3001
|
raise ArgumentError
|
2637
3002
|
end
|
2638
3003
|
end
|
2639
3004
|
|
2640
|
-
|
2641
3005
|
#
|
2642
3006
|
# set attribute of element (要素の属性を編集する)
|
2643
3007
|
# @param [Meteor::Element] elm element (要素)
|
@@ -2718,6 +3082,69 @@ module Meteor
|
|
2718
3082
|
|
2719
3083
|
private :get_attr_value_
|
2720
3084
|
|
3085
|
+
#
|
3086
|
+
# @overload attrs(elm,attrs)
|
3087
|
+
# @param
|
3088
|
+
#
|
3089
|
+
# @overload attrs(elm)
|
3090
|
+
#
|
3091
|
+
def attrs(elm,*args)
|
3092
|
+
case args.length
|
3093
|
+
when ZERO
|
3094
|
+
get_attrs(elm)
|
3095
|
+
when ONE
|
3096
|
+
if args[0].kind_of?(Hash)
|
3097
|
+
if args[0].size == 1
|
3098
|
+
elm.document_sync = true
|
3099
|
+
set_attribute_3(elm, args[0].keys[0], args[0].values[0])
|
3100
|
+
elsif args[0].size >= 1
|
3101
|
+
set_attrs(elm, args[0])
|
3102
|
+
else
|
3103
|
+
raise ArgumentError
|
3104
|
+
end
|
3105
|
+
else
|
3106
|
+
raise ArgumentError
|
3107
|
+
end
|
3108
|
+
else
|
3109
|
+
raise ArgumentError
|
3110
|
+
end
|
3111
|
+
end
|
3112
|
+
|
3113
|
+
#
|
3114
|
+
# get attribute map (属性マップを取得する)
|
3115
|
+
# @param [Meteor::Element] elm element (要素)
|
3116
|
+
# @return [Hash] attribute map (属性マップ)
|
3117
|
+
#
|
3118
|
+
def get_attrs(elm)
|
3119
|
+
attrs = Hash.new
|
3120
|
+
|
3121
|
+
elm.attributes.scan(@@pattern_get_attrs_map) do |a, b|
|
3122
|
+
attrs.store(a, unescape(b))
|
3123
|
+
end
|
3124
|
+
|
3125
|
+
attrs
|
3126
|
+
end
|
3127
|
+
|
3128
|
+
private :get_attrs
|
3129
|
+
|
3130
|
+
#
|
3131
|
+
# set attribute map (要素に属性マップをセットする)
|
3132
|
+
# @param [Meteor::Element] elm element (要素)
|
3133
|
+
# @param [Hash] attr_map attribute map (属性マップ)
|
3134
|
+
# @return [Meteor::Element] element (要素)
|
3135
|
+
#
|
3136
|
+
def set_attrs(elm, attr_map)
|
3137
|
+
if !elm.cx then
|
3138
|
+
elm.document_sync = true
|
3139
|
+
attr_map.each do |name, value|
|
3140
|
+
set_attribute_3(elm, name, value)
|
3141
|
+
end
|
3142
|
+
end
|
3143
|
+
elm
|
3144
|
+
end
|
3145
|
+
|
3146
|
+
private :set_attrs
|
3147
|
+
|
2721
3148
|
#
|
2722
3149
|
# @overload attr_map(elm,attr_map)
|
2723
3150
|
# set attribute map (属性マップをセットする)
|
@@ -2729,15 +3156,15 @@ module Meteor
|
|
2729
3156
|
# @param [Meteor::Element] elm element (要素)
|
2730
3157
|
# @return [Meteor::AttributeMap] attribute map (属性マップ)
|
2731
3158
|
#
|
2732
|
-
def attr_map(
|
3159
|
+
def attr_map(elm,*args)
|
2733
3160
|
case args.length
|
3161
|
+
when ZERO
|
3162
|
+
get_attr_map(elm)
|
2734
3163
|
when ONE
|
2735
|
-
|
2736
|
-
|
2737
|
-
|
2738
|
-
|
2739
|
-
set_attr_map(args[0], args[1])
|
2740
|
-
#end
|
3164
|
+
#if elm.kind_of?(Meteor::Element) && args[0].kind_of?(Meteor::AttributeMap) then
|
3165
|
+
elm.document_sync = true
|
3166
|
+
set_attr_map(elm, args[0])
|
3167
|
+
#end
|
2741
3168
|
else
|
2742
3169
|
raise ArgumentError
|
2743
3170
|
end
|
@@ -2961,7 +3388,7 @@ module Meteor
|
|
2961
3388
|
|
2962
3389
|
if @res then
|
2963
3390
|
#要素
|
2964
|
-
@elm_ = Element.new(tag)
|
3391
|
+
@elm_ = Meteor::Element.new(tag)
|
2965
3392
|
|
2966
3393
|
@elm_.cx = true
|
2967
3394
|
#属性
|
@@ -3296,22 +3723,22 @@ module Meteor
|
|
3296
3723
|
#
|
3297
3724
|
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
3298
3725
|
# @param [String] file_path absolute path of input file (入力ファイルの絶対パス)
|
3299
|
-
# @param [String]
|
3726
|
+
# @param [String] enc character encoding of input file (入力ファイルの文字コード)
|
3300
3727
|
#
|
3301
|
-
def read(file_path,
|
3728
|
+
def read(file_path, enc)
|
3302
3729
|
|
3303
3730
|
#try {
|
3304
|
-
@character_encoding =
|
3731
|
+
@character_encoding = enc
|
3305
3732
|
#ファイルのオープン
|
3306
3733
|
|
3307
3734
|
#読込及び格納
|
3308
3735
|
io = open(file_path, MODE)
|
3309
|
-
|
3736
|
+
parse(io.read)
|
3310
3737
|
#@root.document = @root.document.kconv(get_encoding(), Kconv.guess(@root.document))
|
3311
3738
|
enc = Kconv.guess(@root.document)
|
3312
3739
|
#enc = get_encoding
|
3313
3740
|
if !Kconv::UTF8.equal?(enc) then
|
3314
|
-
@root.document
|
3741
|
+
parse(@root.document.kconv(Kconv::UTF8, enc))
|
3315
3742
|
end
|
3316
3743
|
|
3317
3744
|
#ファイルのクローズ
|
@@ -3700,12 +4127,11 @@ module Meteor
|
|
3700
4127
|
#
|
3701
4128
|
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
3702
4129
|
# @param [String] filePath file path (ファイルパス)
|
3703
|
-
# @param [String]
|
4130
|
+
# @param [String] enc character encoding (エンコーディング)
|
3704
4131
|
#
|
3705
|
-
def read(file_path,
|
3706
|
-
|
3707
|
-
|
3708
|
-
end
|
4132
|
+
#def read(file_path, enc)
|
4133
|
+
# super(file_path, enc)
|
4134
|
+
#end
|
3709
4135
|
|
3710
4136
|
#
|
3711
4137
|
# analyze document (ドキュメントをパースする)
|
@@ -3817,7 +4243,7 @@ module Meteor
|
|
3817
4243
|
private :element_1
|
3818
4244
|
|
3819
4245
|
def element_without_1(tag)
|
3820
|
-
@elm_ = Element.new(tag)
|
4246
|
+
@elm_ = Meteor::Element.new(tag)
|
3821
4247
|
#属性
|
3822
4248
|
@elm_.attributes = @res[1]
|
3823
4249
|
#空要素検索用パターン
|
@@ -4123,6 +4549,27 @@ module Meteor
|
|
4123
4549
|
|
4124
4550
|
private :get_attr_value_r
|
4125
4551
|
|
4552
|
+
#
|
4553
|
+
# get attribute map (属性マップを取得する)
|
4554
|
+
# @param [Meteor::Element] elm element (要素)
|
4555
|
+
# @return [Hash] attribute map (属性マップ)
|
4556
|
+
#
|
4557
|
+
def get_attrs(elm)
|
4558
|
+
attrs = Hash.new
|
4559
|
+
|
4560
|
+
elm.attributes.scan(@@pattern_get_attrs_map) do |a, b|
|
4561
|
+
attrs.store(a, unescape(b))
|
4562
|
+
end
|
4563
|
+
|
4564
|
+
elm.attributes.scan(@@pattern_get_attrs_map2) do |a|
|
4565
|
+
attrs.store(a[0], TRUE)
|
4566
|
+
end
|
4567
|
+
|
4568
|
+
attrs
|
4569
|
+
end
|
4570
|
+
|
4571
|
+
private :get_attrs
|
4572
|
+
|
4126
4573
|
#
|
4127
4574
|
# get attribute map of element (要素の属性マップを取得する)
|
4128
4575
|
# @param [Meteor::Element] elm element (要素)
|
@@ -4136,7 +4583,7 @@ module Meteor
|
|
4136
4583
|
end
|
4137
4584
|
|
4138
4585
|
elm.attributes.scan(@@pattern_get_attrs_map2) do |a|
|
4139
|
-
attrs.store(a, TRUE)
|
4586
|
+
attrs.store(a[0], TRUE)
|
4140
4587
|
end
|
4141
4588
|
|
4142
4589
|
attrs.recordable = true
|
@@ -4464,12 +4911,11 @@ module Meteor
|
|
4464
4911
|
#
|
4465
4912
|
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
4466
4913
|
# @param file_path file path (ファイルパス)
|
4467
|
-
# @param
|
4914
|
+
# @param enc character encoding (エンコーディング)
|
4468
4915
|
#
|
4469
|
-
def read(file_path,
|
4470
|
-
|
4471
|
-
|
4472
|
-
end
|
4916
|
+
#def read(file_path, enc)
|
4917
|
+
# super(file_path, enc)
|
4918
|
+
#end
|
4473
4919
|
|
4474
4920
|
#
|
4475
4921
|
# analyze document (ドキュメントをパースする)
|
@@ -5120,18 +5566,18 @@ module Meteor
|
|
5120
5566
|
# set document in parser (ドキュメントをパーサにセットする)
|
5121
5567
|
# @param [String] document document (ドキュメント)
|
5122
5568
|
#
|
5123
|
-
def parse(document)
|
5124
|
-
|
5125
|
-
end
|
5569
|
+
#def parse(document)
|
5570
|
+
# @root.document = document
|
5571
|
+
#end
|
5126
5572
|
|
5127
5573
|
#
|
5128
5574
|
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
5129
5575
|
# @param file_path file path (ファイルパス)
|
5130
|
-
# @param
|
5576
|
+
# @param enc character encoding (エンコーディング)
|
5131
5577
|
#
|
5132
|
-
def read(file_path,
|
5133
|
-
|
5134
|
-
end
|
5578
|
+
#def read(file_path, enc)
|
5579
|
+
# super(file_path, enc)
|
5580
|
+
#end
|
5135
5581
|
|
5136
5582
|
# get content type (コンテントタイプを取得する)
|
5137
5583
|
# @return [Streing] content type (コンテントタイプ)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meteor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.7.
|
4
|
+
version: 0.9.7.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A lightweight (X)HTML(5) & XML parser
|
15
15
|
email: ys.ashida@gmail.com
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project: meteor
|
61
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.25
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
64
|
summary: A lightweight (X)HTML(5) & XML parser
|