Class: RSM

Inherits:
Object
  • Object
show all
Defined in:
lib/rsm.rb

Instance Method Summary collapse

Constructor Details

#initializeRSM

Returns a new instance of RSM.



74
75
76
77
78
79
80
81
82
# File 'lib/rsm.rb', line 74

def initialize
	@block = false
	@prev_block = false
	@styles = ''
	@css = ''
	@attr = false #for attrs with dash
	@tag_class = false #for div.class
	@includes = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rsm.rb', line 88

def method_missing sym, *args, &block
	if @block
		if not block.nil? and @prev_block
			#body{div{p{
			process_style sym, *args, &block
		end
		@css += " {\r\n" if @prev_block
		if block.nil?
			if args.empty?
				if @includes.include? sym
					@css += @includes[sym]
				else
					@css+="\t#{sym}-"
					@attr = true
				end
			else
				@css += "\t" unless @attr
				@css+="#{sym}: #{args.join(" ")}\r\n"
				@attr = false
			end
		end
		@prev_block = false
	else
		if block.nil? and args.empty?
			@css += sym.to_s
		elsif sym.to_s[-1] == ?!
			r = RSM.new
			r.block = true
			r.markup &block
			@includes[sym] = r.to_s
		else
			@block = true
			@prev_block = true
			process_style sym, args, &block
			@block = false
			@css += "}\r\n\r\n"
			@tag_class = false
		end
	end
	self
end

Instance Method Details

#block=(val) ⇒ Object



84
85
86
# File 'lib/rsm.rb', line 84

def block= val
	@block = val
end

#markup(str = nil, &block) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/rsm.rb', line 144

def markup str=nil, &block
	if str.nil?
		instance_eval &block
	else
		instance_eval str
	end
end

#process_style(name, *args, &block) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rsm.rb', line 130

def process_style name, *args, &block
	if name.to_s[0] == ?_
		@css += "##{name.to_s[1..-1]}"
	elsif Tags.include? name.to_s.split('_')[0].to_sym
		@css += "." if @tag_class
		@css += "#{name.to_s.split('_').join(', ')} "
		@prev_class = true if block.nil?
		@tag_class = true if block.nil?
	else
		@css += ".#{name} "
	end
	instance_eval &block unless block.nil?
end

#to_sObject



152
153
154
# File 'lib/rsm.rb', line 152

def to_s
	@css
end