Code Monkey home page Code Monkey logo

gocss's Introduction

Gocss

Gocss is a simple css parser written in GO, that provides a way to parse css selectors and properties.

Installation

$>go get github.com/m2omou/parser-css/src
import "github.com/m2omou/parser-css/src"

Code examples

####Type:####

The different type of selector, 'All' stand for the '*' css selector

const ( 
	Class = 1
	Id
	All
	Element
	Attribute
)

####Property:####

e.g: "color: white;"

type property struct {
        Name string 		// color
        Value string 		// white
}

####Selector:####

e.g ".container { color: white, float: left }"

type selector struct {
        Name string             // '.container'
        Properties []property   // [ { Name : 'color', Value : 'white' }, { Name : 'float', Value : 'left'} ]
        Type int                // Class
}

fd, err := os.Open("./style.css")
    
if err != nil {
        panic(err)
}
        
css := parserCSS(fd)
for s := range selectors {
        fmt.Println(selectors[s].Name)
        for p := range selectors[s].Properties {
                fmt.Println(selectors[s].Properties[p].Name + selectors[s].Properties[p].Value)
        }
}

For example this css :

body {
    width: 100%;
    height: 100%;
    Background: red;
}

.container {
    margin-bottom: 20px;
    height: 220px;
    width:300px;
    font-size: 14px;
}

Will return the following slice :

[
   {
      "Name":"body",
      "Properties":[
         {
            "Name":"width",
            "Value":"100%"
         },
         {
            "Name":"height",
            "Value":"100%"
         },
         {
            "Name":"Background",
            "Value":"red"
         }
      ],
      "Type":1
   },
   {
      "Name":".container",
      "Properties":[
         {
            "Name":"margin-bottom",
            "Value":"20px"
         },
         {
            "Name":"height",
            "Value":"220px"
         },
         {
            "Name":"width",
            "Value":"300px"
         },
         {
            "Name":"font-size",
            "Value":"14px"
         }
      ],
      "Type":1
   }
]

License

GOCSS Parser Copyright 2014 Mourad Sabour, mourad.sabour[at]gmail.com.

gocss's People

Contributors

m2omou avatar

Stargazers

sparks of fire avatar  avatar  avatar Marcus Yearwood avatar Morgan Collino avatar

Watchers

James Cloos avatar  avatar

gocss's Issues

Problems importing the Package

I am having trouble importing the library into my Go program. When I add the import statement and run,

 go get .

I get a host of errors.

.\parse_css.go:9: main redeclared in this block
        previous declaration at .\parse_css.go:4
.\parse_css.go:11: newline in string
.\parse_css.go:14: syntax error: unexpected semicolon or newline
.\parse_css.go:15: syntax error: unexpected semicolon or newline
.\parse_css.go:19: syntax error: unexpected .
.\parse_css.go:20: malformed fp constant exponent
.\parse_css.go:21: malformed fp constant exponent
.\parse_css.go:21: non-declaration statement outside function body
.\parse_css.go:21: syntax error: unexpected name, expecting semicolon or newline
.\parse_css.go:22: malformed fp constant exponent
.\parse_css.go:22: too many errors

If I run

go get github.com/m2omou/parser-css/src

it runs without any output, but then when I run

go build

it says,

file.go:4: can't find import: "github.com/m2omou/parser-css/src"

Licence - Fork

Hi,

i want to fork gocss for my own project but i do not find any licence. Can i use it? Is it opensource? What to do?

Unable to import package

Thanks for writing gocss.

I'm fairly new to go, and am currently trying to use gocss. When trying to compile your examples, or any other code that references the package, I get the following error:

can't load package: /Users/joe/Development/CSSCounter/counter.go:6:2: import "github.com/m2omou/parser-css/src" is a program, not an importable package

Some googling suggests that this may be because gocss uses main as it's package -- but I don't know if that's the actual issue.

Any pointers? Am I doing something wrong? I go version outputs: go version go1.7.3 darwin/amd64.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.