html_gen 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "knjrbfw"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.8.0"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "bundler", ">= 1.0.0"
14
+ gem "jeweler", "~> 1.8.4"
15
+ end
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ datet (0.0.14)
5
+ diff-lcs (1.1.3)
6
+ git (1.2.5)
7
+ http2 (0.0.5)
8
+ jeweler (1.8.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rdoc
13
+ json (1.7.4)
14
+ knjrbfw (0.0.78)
15
+ datet
16
+ http2
17
+ php4r
18
+ tsafe
19
+ wref
20
+ php4r (0.0.2)
21
+ datet
22
+ http2
23
+ rake (0.9.2.2)
24
+ rdoc (3.12)
25
+ json (~> 1.4)
26
+ rspec (2.8.0)
27
+ rspec-core (~> 2.8.0)
28
+ rspec-expectations (~> 2.8.0)
29
+ rspec-mocks (~> 2.8.0)
30
+ rspec-core (2.8.0)
31
+ rspec-expectations (2.8.0)
32
+ diff-lcs (~> 1.1.2)
33
+ rspec-mocks (2.8.0)
34
+ tsafe (0.0.11)
35
+ wref (0.0.5)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (>= 1.0.0)
42
+ jeweler (~> 1.8.4)
43
+ knjrbfw
44
+ rdoc (~> 3.12)
45
+ rspec (~> 2.8.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Kasper Johansen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = html_gen
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to html_gen
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "html_gen"
18
+ gem.homepage = "http://github.com/kaspernj/html_gen"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A small framework for generating HTML.}
21
+ gem.description = %Q{A small framework for generating HTML.}
22
+ gem.email = "k@spernj.org"
23
+ gem.authors = ["Kasper Johansen"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "html_gen #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,8 @@
1
+ class Html_gen
2
+ #Autoloader for subclasses.
3
+ def self.const_missing(name)
4
+ require "#{File.dirname(__FILE__)}/html_gen_#{name.to_s.downcase}.rb"
5
+ raise "Still not defined: '#{name}'." if !Html_gen.const_defined?(name)
6
+ return Html_gen.const_get(name)
7
+ end
8
+ end
@@ -0,0 +1,113 @@
1
+ require "knjrbfw"
2
+
3
+ class Html_gen::Element
4
+ attr_accessor :attr, :css, :classes, :str, :html
5
+
6
+ def initialize(name, args = {})
7
+ if args[:attr]
8
+ @attr = args[:attr]
9
+ else
10
+ @attr = {}
11
+ end
12
+
13
+ raise "'name' should be a string or a symbol but was a '#{name.class.name}'."if !name.is_a?(String) and !name.is_a?(Symbol)
14
+
15
+ @name = name
16
+
17
+ {:classes => [], :html => "", :str => "", :css => {}, :eles => [], :nl => "\n", :inden => "\t"}.each do |arg, default_val|
18
+ if args[arg]
19
+ instance_variable_set("@#{arg}", args[arg])
20
+ else
21
+ instance_variable_set("@#{arg}", default_val)
22
+ end
23
+ end
24
+ end
25
+
26
+ def add_ele(name, args = {})
27
+ ele = Html_gen::Element.new(name, args)
28
+ @eles << ele
29
+ return ele
30
+ end
31
+
32
+ def html(args = {})
33
+ if args[:level]
34
+ level = args[:level]
35
+ else
36
+ level = 0
37
+ end
38
+
39
+ if args.key?(:pretty)
40
+ pretty = args[:pretty]
41
+ else
42
+ pretty = true
43
+ end
44
+
45
+ pass_args = {:level => (level + 1), :pretty => pretty}
46
+
47
+ attr = @attr.clone
48
+ classes = @classes.clone
49
+
50
+ str = ""
51
+ str << @inden * level if pretty and level > 0
52
+ str << "<#{@name}"
53
+
54
+ if !@css.empty?
55
+ style = ""
56
+ @css.each do |key, val|
57
+ style << "; " if !style.empty?
58
+ style << "#{key}: #{val};"
59
+ end
60
+
61
+ if attr[:style] and !attr[:style].empty?
62
+ attr[:style] << "; "
63
+ attr[:style] << style
64
+ else
65
+ attr[:style] = style
66
+ end
67
+ end
68
+
69
+ if !@classes.empty?
70
+ class_str = @classes.join(" ")
71
+
72
+ if @attr[:class] and !@attr[:class].empty?
73
+ @attr[:class] << " #{class_str}"
74
+ else
75
+ @attr[:class] = class_str
76
+ end
77
+ end
78
+
79
+ attr.each do |key, val|
80
+ str << " #{key}=\"#{Knj::Web.html(val)}\""
81
+ end
82
+
83
+ if @eles.empty? and @str.empty? and @html.empty?
84
+ str << " />"
85
+ str << @nl if pretty
86
+ else
87
+ str << ">"
88
+ str << @nl if pretty
89
+
90
+ if !@str.empty?
91
+ str << @inden * (level + 1) if pretty
92
+ str << Knj::Web.html(@str)
93
+ str << @nl if pretty
94
+ end
95
+
96
+ if !@html.empty?
97
+ str << @inden * (level + 1) if pretty
98
+ str << @html
99
+ str << @nl if pretty
100
+ end
101
+
102
+ @eles.each do |subele|
103
+ str << subele.html(pass_args)
104
+ end
105
+
106
+ str << @inden * level if pretty and level > 0
107
+ str << "</#{@name}>"
108
+ str << @nl if pretty
109
+ end
110
+
111
+ return str
112
+ end
113
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "HtmlGen" do
4
+ it "should be able to generate html" do
5
+ html = Html_gen::Element.new(:td, :classes => [:test]).html
6
+ raise "Expected valid HTML." if html != "<td class=\"test\" />"
7
+
8
+ html = Html_gen::Element.new(:td, :attr => {:colspan => 2}).html
9
+ raise "Expected valid HTML." if html != "<td colspan=\"2\" />"
10
+
11
+ html = Html_gen::Element.new(:td, :css => {:width => "80px"}).html
12
+ raise "Expected valid HTML: '#{html}'." if html != "<td style=\"width: 80px;\" />"
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'html_gen'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_gen
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Kasper Johansen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-08-10 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: knjrbfw
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.8.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rdoc
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: "3.12"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.0.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: jeweler
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.8.4
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ description: A small framework for generating HTML.
72
+ email: k@spernj.org
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files:
78
+ - LICENSE.txt
79
+ - README.rdoc
80
+ files:
81
+ - .document
82
+ - .rspec
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ - Rakefile
88
+ - VERSION
89
+ - lib/html_gen.rb
90
+ - lib/html_gen_element.rb
91
+ - spec/html_gen_spec.rb
92
+ - spec/spec_helper.rb
93
+ has_rdoc: true
94
+ homepage: http://github.com/kaspernj/html_gen
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: -1933339893132629672
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project:
120
+ rubygems_version: 1.6.2
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: A small framework for generating HTML.
124
+ test_files: []
125
+