2013-07-19 3 views
0

일부 클래스가 포함 된 all.css 파일을 사용하려고하는데 녹색 클래스 만 포함 된 green.css 파일을 가져 오려고합니다.파일에서 특정 CSS 클래스 추출

나는 내가 그것을 사용하는 방법에 대한 제안이 .green을 포함하는 행을 검색하고 {로 끝나는 다음 CSS 블록을 추출, perlCSS 모듈을 사용하고 있습니다?

나는 내가 그냥 "녹색"과 일치하는 선택 라인을 인쇄하려고 지금까지, 펄 새로운 해요하지만 난이 동작하지 않습니다 :

my $css = CSS->new({ 'parser' => 'CSS::Parse::Lite'}); 

print $styleSheetPath; 
$css->read_file($styleSheetPath); 

open my $fileHandle, ">>", "green.css" or die "Can't open 'green.css'\n"; 

#search for lines that contain .green and end { and then extract css block 
#and write to green.css 
serialize($css); 

sub serialize{ 
     my ($obj) = @_; 

    for my $style (@{$obj->{styles}}){ 
     print join "\n ", map {$_->{name}} @{$style->{selectors}}; 
     if (grep(/green/, @{$style->{selectors}})) { 
      print "green matches "; 
      print $_->{name}; 
     } 

     } 
} 
+0

@innaM edited my question –

답변

2

IT는의 documentation를 읽을 수 있습니다 귀하가 작업하고있는 소프트웨어. 스타일을 찾으려면 메서드를 .green 인수와 함께 호출하십시오.

use CSS qw(); 
my $css = CSS->new; 
$css->read_string('.red { clear: both; } .green { clear: both; }'); 
$css->get_style_by_selector('.green')->to_string;