Search cssutils.py parse tree by ID and CLASS selectors - css-parsing

I'm using cssutils in Python to parse CSS style files and would like to search the parse tree by ID and Class. That is, given some CSS style file and some Class name (e.g. div navbar), how do I ascertain the style rules encapsulated by this selector? A solution or any ideas about where to look in the existing documentation (http://packages.python.org/cssutils/index.htm) would be highly appreciated

You can try this out:
import cssutils
css_parser = cssutils.CSSParser()
stylesheet = css_parser.parseUrl(CSS_URL)
for each_rule in stylesheet.CSSRules:
if ID_NAME in each_rule.selectorText:
print each_rule.style
Similarly you can try for CLASS_NAME as well.
Would this work for you?

Related

How to get Grails not to escape html tags generated by CK Editor

This question was asked and answered in 2012. Unfortunately, none of the answers work with Grails 3.3.8 and the Fields plugin. I tried ${raw(value)} and whatever I could find. It still shows things like <b>Hello </b> <em>world</em>. ${raw(value)} is recommended in the latest Grails documentation here
I'm stuck and will appreciate any ideas.
OK, this is how one does it:
First, you need Unbescape. Add this to build.gradle:
compile "org.unbescape:unbescape:1.1.6.RELEASE" // to unbescape html
Next do grails create-tag-lib Unbescape. Here's your whole tag lib class:
import org.unbescape.*
import org.unbescape.html.*
class UnbescapeTagLib {
static defaultEncodeAs = [taglib:'text']
//static encodeAsForTags = [tagName: [taglib:'html'], otherTagName: [taglib:'none']]
static final namespace = 'ubs'
def unescape = {attrs, body ->
out << HtmlEscape.unescapeHtml(body.call().toString())
}
}
Now create a directory called 'show' and inside that a directory called 'description'. This is of course in your views directory for the particular domain object. Description is the name of the field. Inside the directory 'description' create a file called _displayWidget.gsp. This is what the file looks like:
<ubs:unescape>${raw(value)}</ubs:unescape>
Calling the raw function on value returns a org.grails.taglib.TagBodyClosure object which is passed to your tag lib. That's why you have to do a call on the body and turn the result to a String in your tag lib.
This is easy to implement if one knows how to do it, but finding out how to do it was not easy. The documentation is not good. The Fields plugin really complicated things a lot. Before Fields, this was easy to do.

Access process i18n property files before compilation

I have a following situation: in some of my i18n property files there are properties containing a special word:
prop.example=specialword just for example
prop.test=just for test specialword
I want to have a possibility of having a property somewhere in my Config.groovy that would contain a specific value for this specialword so that if I specify:
specialword=Value of special word
in a Config.groovy then I want my i18n properties to be resolved like:
prop.example=Value of special word just for example
prop.test=just for test Value of special word
for that purpose, when building the project, I want to access property files in order to look for occurences of specialword and to replace them with value of specialwordvalue from Config.groovy.
Is that possible somehow? Perhaps, someone faced similar situation? I would really appreciate any help.
Thanks, Cheers
Instead of trying to change the way the properties are compiled, you would be better off passing the special value as an argument to your message code (as discussed in the comments to your question).
For instance:
<g:message code="my.key.code" args="[someVariableWithAValueFromConfig]" />
If your message code doesn't use the argument it will simply be ignored. This seems like the best approach to the problem you are trying to solve.

Twig, ZF2 and PoEdit

Using ZfcTwig for ZF2 and twig-gettext-extractor, I still cannot extract messages for translation from twig-files by poedit. I works if I used the formal twig keyword for translation {% trans(MY_TEXT) %} but not for the in-built view helper translate. {{ translate(MY_Text) }} does the translation but poedit is just ignoring it. For new twig files, I want as usual let poedit do the job....
Any ideas for a solution?
Maybe you need to edit catalog properties keywords to be visible for translations. Open PoEdit, go to Catalog -> Properties -> Sources keywords and add another keyword "translate". Here I attach an screenshot.
The problem is that the extractor you are using is just caching the files and running them through xgettext to extract calls to trans/translate/_/.. (keywords as suggested by Conti. Alas ZfcTwig will crosscompile calls to ZF2 plugins into plugin('translate')->__invoke('Your Text to be translated'). You could of course now add __invoke as a new keyword in poedit or whatever you favorite gui for using xgettext is, but it will now find all calls to all view helpers not just those to translate.
I ran into this problem myself and I have not come up with a satisfying solution. The Twig Gettext Extension looks promising in terms of writing your own customized POT-File generator that will handle translate and translatePlural view helper calls. Using the extension as is will bypass all translation from ZF2. ZF2 parses .mo files into an internal structure rather than using the php-gettext mod.
All in all I gave up on automated po(t) file generation for ZF2+ZfcTwig for now and am back to phpArray.

Xtext: refering objects from other languages; namespaces and aliases for importURI?

I'm developing a xtext-based language which should refer to objects defined in a vendor-specific file format.
E.g. this file format defines messages, my language shall define Rules that work with these messages. Of course i want to use xtext features e.g. to autocomplete/validate message names, attributes etc.
Not sure if that is a good idea, but I came up with the following:
Use one xtext project to describe the file format
Add a dependency for this project to my DSL project, import the file format grammar to my grammar
import the description files via importURI
FileFormat grammar:
grammar com.example.xtext.fileformat.FileFormat;
generate fileformat "http://xtext.example.com/fileformat/FileFormat"
[...]
DSL grammar:
grammar com.example.xtext.dsl.DSL;
import "http://xtext.example.com/fileformat/FileFormat" AS ff;
Model:
rules += Rule*;
Rule: ImportFileRule | SampleRule;
ImportFileRule: "IMPORT" importURI=STRING "AS" name=ID ";";
SampleRule: "FORWARD" msg=[ff::Message] ";"
First of all: This works fine.
Now, different imported files may define messages with colliding names,
and I want to use fully qualified names for messages anyways.
The prefix for the message names should be defined in my DSL, e.g. the name of the ImportFileRule.
So I would like to use something like:
IMPORT "first-incredibly-long-filename-with-version-and-stuff.ff" AS first;
IMPORT "second-incredibly-long-filename-with-version-and-stuff.ff" AS second;
FORWARD first.msg_1; // references to msg_1 in first file
FORWARD second.msg_1; // references to msg_1 in second file
Unfortunately I don't see a easy way to achieve this with xtext.
At the moment I'm using a ID for the namespace qualifier and custom ProposalProvider/Validator classes,
which is ugly in detail and bypasses the EMF index, becoming slow with files of 1000 messages and 50000 attributes...
Would there be a right way to do it?
Was it a good idea to use xtext to parse the definition files in the first place?
I have two ideas what to check.
Xtext has a specific global scope provider called ImportedNameSpaceAwareScopeProvider. By using an overridden version of this, you could specify other headers to consider.
Check the implementation of the xtext grammar itself, as it supports such a feature with EPackage imports. I am not exactly sure, how it operates, but should work this way.
Finally, I ended up using the SimpleNamesFragment, ImportURIScopingFragment and a custom ScopeProvider derived from AbstractDeclarativeScopeProvider.
That way, I had to implement ScopeProvider methods for quiet a few rules but was much more flexible in using my "namespace prefix".
E.g. it is simple to implement syntaxes like
FORWARD FROM first: msg_01, msg_02;

Rails + bootstrap-sass mixins

Maybe I don't understand how to use mixin with sass, or how to work with the ones with bootstrap-sass (https://github.com/thomas-mcdonald/bootstrap-sass). But how can I do something like change the box-shadow on a class of input fields?
EDIT: Should clarify, in this example I'm trying to change the glow effect on an active input field when it is selected. By default it's blue.
For my project setup, I have it just like it says on the github page and have the gem in the Gemfile and then in a controller I have something like:
#import "bootstrap"
.testInput {
/*(here I have put a variation of variables that I change to see
if I can do something with the mixin like $bordercolor: #000;*/
#include formFieldState()
}
So maybe my understanding of how sass works is way off. I guess if I wanted to change the box-shadow for inputs I could just repeat the code in my own mixin but it was also just kind of a general question on if this kind of thing was possible with the other mixins as well.
Did you look at the source to see what the formFieldState mixin does? It lives here: https://github.com/thomas-mcdonald/bootstrap-sass/blob/master/vendor/assets/stylesheets/bootstrap/_mixins.scss#L159. It looks like this mixin is designed to be used within some type of container, most likely a form.
There are no variables controlling the default input:focus box-shadow (its declaration is here: https://github.com/thomas-mcdonald/bootstrap-sass/blob/master/vendor/assets/stylesheets/bootstrap/_forms.scss#L126). You'll have to override it the old fashioned way.
You should put the things you want to change after the #include, instead of before. The last declaration wins with CSS so if you put them before the mixin, the mixin version will win.
See here: http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/ for an advanced discussion of CSS precedence.

Resources