class WidgetBuilder::Widgets

Crates an array of Widgets by passing in the paths to the html, css, and js directories

Public Class Methods

new(html_path = '.', css_path = '.', js_path = '.', options = {}) click to toggle source
# File lib/widget_builder.rb, line 148
def initialize(html_path = '.', css_path = '.', js_path = '.', options = {})
        @html_path, @css_path, @js_path, @options = html_path, css_path, js_path, options
        @widgets = widgets
end

Public Instance Methods

compile(path = File.dirname(@js_path)) click to toggle source
# File lib/widget_builder.rb, line 185
def compile(path = File.dirname(@js_path))
        widgets.each { |widget| widget.compile(path) }
end
report() click to toggle source
# File lib/widget_builder.rb, line 181
def report
        widgets.each { |widget| widget.report }
end
save(path = @js_path) click to toggle source
# File lib/widget_builder.rb, line 177
def save(path = @js_path)
        widgets.each { |widget| widget.save(path) }
end
widgets() click to toggle source
# File lib/widget_builder.rb, line 153
def widgets
        widgets = []
        Dir.foreach(@html_path) do |file| # read all the files in the 'Widget html' directory
                if (file.match(/\.html$/)) # only consider html files for now
                        html_path = File.join(@html_path, file)

                        # HTML, CSS, and JS files should have the same name but different extensions
                        filename = file.gsub('.html', '')

                        css_path = ''
                        Find.find(@css_path) do |path|
                                css_path = path if path.split('/').last.match(/^#{filename}.*?\.(?:css|scss|sass)$/)
                        end

                        js_path = ''
                        Find.find(@js_path) do |path|
                                js_path = path if path.split('/').last.match(/^#{filename}\.js$/) # NOTE: Needs to add CoffeeScript support
                        end
                        widgets << WidgetBuilder::Widget.new(html_path, css_path, js_path, @options)
                end
        end
        widgets
end