rudsl 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74cf90e7dd03c01c8f93cc424e4ef597c63c5927
4
+ data.tar.gz: dbb422617e3192207c1f57d799f710d895eae54c
5
+ SHA512:
6
+ metadata.gz: 969163c2a141113301cc34c2c51665579550b70eca8ce5cfb0fa905e42f6e99202d8e412edd1890b62843a83edf0e8c41997c4d91511a0113b4ca686d8469085
7
+ data.tar.gz: 22f55f641ab8e154c90837f61a0a3c4574140e9751ccf91fe05811d7cbec6e5f2d62288b92031db942185b1819bfa3f115ed2e682ff0d287eb713b02827964c8
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rudsl.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ajith Hussain
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Rudsl
2
+
3
+ Rudsl is a functional DSL in Ruby, for generating HTML (and eventually, CSS).
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rudsl'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rudsl
21
+
22
+ ## Usage
23
+
24
+ ### Example 1
25
+
26
+ ```ruby
27
+ include Rudsl
28
+
29
+ node = div class:'list-container' do
30
+ ul do
31
+ %w(Hello world).each do |word|
32
+ li word
33
+ end
34
+ end
35
+ end
36
+
37
+ node.to_s # will return "<div class="list-container"><ul><li>Hello</li><li>world</li></ul></div>"
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( https://github.com/[my-github-username]/rudsl/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,64 @@
1
+ require "rudsl/version"
2
+
3
+ module Rudsl
4
+ Nodes = %w(a abbr acronym address applet area article aside audio b base basefont bdi bdo big blockquote body br button canvas caption center cite code col colgroup datalist dd del details dfn dialog dir div dl dt em embed fieldset figcaption figure font footer form frame frameset h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins kbd keygen label legend li link main map mark menu menuitem meta meter nav noframes noscript object ol optgroup option output p param pre progress q rp rt ruby s samp script section select small source span strike strong style sub summary sup table tbody td textarea tfoot th thead time title tr track tt u ul var video wbr)
5
+
6
+ Nodes.each do |n|
7
+ module_eval do
8
+ define_method(n) do |*attributes, &block|
9
+ node = Node.new(n)
10
+ attrs = attributes.last.is_a?(Hash) ? attributes.last : {}
11
+ text = attributes.first.is_a?(String) ? attributes.first : nil
12
+ node.text = text
13
+ node.attributes = attrs
14
+
15
+ @_node_stack ||= []
16
+
17
+ if !@_node_stack.last.nil?
18
+ @_node_stack.last.children << node
19
+ end
20
+
21
+ if !block.nil?
22
+ @_node_stack << node
23
+ block.call
24
+ @_node_stack.pop
25
+ end
26
+
27
+ node
28
+ end
29
+ end
30
+ end
31
+
32
+ class Node
33
+ attr_accessor :node_type
34
+ attr_accessor :attributes
35
+ attr_accessor :children
36
+ attr_accessor :text
37
+
38
+ def initialize(node_type)
39
+ @node_type = node_type
40
+ @attributes = {}
41
+ @children = []
42
+ @text = nil
43
+ end
44
+
45
+ def to_s
46
+ "<#{@node_type}#{@attributes.to_a.count == 0 ? "" : " "}#{@attributes.to_a.map{|e| "#{e[0]}=\"#{e[1].is_a?(Array) ? e[1].join(" ") : e[1]}\""}.join(" ")}>" + @text.to_s + @children.map(&:to_s).join("") + "</#{@node_type}>"
47
+ end
48
+
49
+ def removeClass(classToRemove)
50
+ if !attributes[:class].nil?
51
+ attributes[:class].delete(classToRemove)
52
+ end
53
+ end
54
+
55
+ def addClass(classToAdd)
56
+ if attributes[:class].is_a?(String) || attributes[:class].is_a?(Symbol)
57
+ attributes[:class] = [attributes[:class].to_s]
58
+ end
59
+ attributes[:class] ||= []
60
+ attributes[:class] << classToAdd.to_s
61
+ attributes[:class].uniq!
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module Rudsl
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rudsl/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rudsl"
8
+ spec.version = Rudsl::VERSION
9
+ spec.authors = ["Ajith Hussain"]
10
+ spec.email = ["csy0013@googlemail.com"]
11
+ spec.summary = %q{A functional HTML and CSS dsl in Ruby}
12
+ spec.description = %q{rudsl provides a function dsl in Ruby, for HTML and CSS.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rudsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ajith Hussain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: rudsl provides a function dsl in Ruby, for HTML and CSS.
42
+ email:
43
+ - csy0013@googlemail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/rudsl.rb
54
+ - lib/rudsl/version.rb
55
+ - rudsl.gemspec
56
+ homepage: ''
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A functional HTML and CSS dsl in Ruby
80
+ test_files: []