2009-12-01 131 views
0

我認爲,CSS語法和基本原則可以非常有用,而不僅僅適用於樣式。 是否有任何PARSE引擎可以使用類似CSS的規則操作,就像XML的規則一樣?CSS語法不適用於STYLE


例如,我們可以創建類似框架(是的,另一個),其中我們在XML中定義的頁面風格(JUST例如,也許很愚蠢或兩個複雜):

<page id="index" url="/" controller="staticpage" /> 
<page id="about" url="/" controller="staticpage" action="about" /> 
<page id="post" url="/post/(\d+)" type="regex" controller="post" class=""> 
    <param id="1" name="post_id" /> 
</page> 
<page id="post_comment" url="/comment/(\d+)" type="regex" controller="post" action="comment" class="authneeded"> 
    <param id="1" name="post_id" /> 
</page> 
<page id="post_write" url="/write" type="regex" controller="staticpage" action="write" class="authneeded" /> 

然後寫一個「CSS」:

* { 
    layout: "layout.html"; // default layout 
} 
*[action=''] { 
    action: "index"; // default action 
} 
#post_write { 
    layout: "adminlayout.html"; 
} 
.authneeded { 
    redirect: "/"; 
} 
.authneeded:loggedin { // pseudoclass which is set only if the user logged in. 
         // (maybe POSTS:loggedin .authneeded to apply only one 
         // pseudoclass) 

    redirect: false; // no, we don't need to redirect then the user logged in 
} 

這不是一個有趣的配置方式嗎? 更妙的是,我們可以創建一個管理腳本(的jQuery的啓發;)

./admin #about addClass authneeded 
./admin "#post PARAM" attr id param_post 

那麼,有沒有可以與CSS類規則的操作任何引擎?

+0

這樣做有沒有什麼好處,而不是堅持標準的metaformats? (見http://www.faqs.org/docs/artu/ch05s02。html)你有一個有趣的想法,但是什麼是錯誤的,例如,爲此使用YAML? – deau 2009-12-01 19:22:25

+0

這看起來像JSON的工作! – 2009-12-01 19:22:59

+0

在json中沒有選擇器 – 2009-12-01 20:15:23

回答

0

不完全是CSS,但自從您提到XML以來,始終存在XSLT,它可用於以不同方式轉換XML。例如,您可以從簡單的XML文件等構建HTML列表。

+0

不,我想要一個CSS解析器 – 2009-12-01 20:17:20

+0

也許你應該在你的問題中說「我想要一個CSS解析器」。 – 2009-12-01 20:27:38

-1

我想說它已經完成了?下面是一些在grails & django中的url映射。它不是CSS,但是再一次,CSS應該包含style而不是actions,並且語法沒有那麼不同。

Grails中,UrlMapping.groovy可能類似於:

class UrlMappings { 
    static mappings = { 
     "/$controller/$action?/$id?"{ 
     constraints { 
     // apply constraints here 
     } 
    } 
    "/"(controller:"static") 
    "500"(view:'/error') 
    "/product/" (controller:"myController", action:"show") 
    "/old/**" (view:"/index") 
    "/uploads/$requestedFile**" (controller:"processFile") 
    } 
} 

在蟒蛇:

urlpatterns = patterns('', 
    # Example: 
    (r'^$', direct_to_template, {'template': 'pages/front.html' }), 
    (r'^about/',direct_to_template, {'template': 'pages/about.html' }), 
    (r'^demo/',direct_to_template, {'template':'pages/demo.html'}), 
    (r'^accounts/', include('apps.accounts.urls')), 
    (r'^forms/', include('apps.forms.urls')), 
    (r'^admin/doc/', include('django.contrib.admindocs.urls')), 
    (r'^admin/(.*)', admin.site.root), 
    {'document_root': settings.MEDIA_ROOT}), 
) 

我個人的偏好是Grails的,這恰好接近類似於您介紹的腳本。在Grails中,大部分網址/動作都會由您的控制器自動生成,因此您不需要該配置,但在世界不太完美的情況下可以使用)。

+0

我不需要框架,我需要一個CSS解析器 – 2009-12-01 20:14:37

0

我已經看到了Mac的HTML/CSS編輯器演示,使用CSS選擇器來生成HTML標記。不記得該程序的名稱,但它似乎是一個非常優雅和有效的方式來編寫HTML。

給你它是如何工作的想法,可以說你在編輯器中這樣寫:

ul#navigation li a.active 

而按一些神奇的快捷鍵(或只是輸入)將其轉換成這樣:

<ul id="navigation"> 
    <li><a class="active"></a></li> 
</ul> 

對我來說,這看起來像是CSS的邏輯用法。正如你所描述的那樣,將它用於元數據可能會有用,如果你想將它分開。

然而在你的例子中,兩者關係非常密切。並且在XML中設置默認值和條件是很有意義的(就像param標籤一樣)。

+0

是的,我已經看到了:)我將檢查他們正在使用的解析器,謝謝 – 2009-12-01 20:39:53

+0

我認爲你所指的是Zen Coding - http:/ /code.google.com/p/zen-coding/。它是許多編輯的插件,並且在Mac上由Espresso本地支持。 – 2012-01-20 17:53:47