Sha256: 2227699e413f8c8181db7428f5647d7c7d041caae1c9e9ff15cfbeffea77b54a

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'erb'

module Parse
    module Model
        module Scaffold

            class ParseClassBuilder

                @@supported_types = [:coffee, :objc]

                def initialize (class_name, attrs)
                    @class_name = class_name
                    @attrs = attrs
                end

                def build (types = nil)

                    types ||= supported_types

                    types.each do |type|

                        templates = Dir.glob "./lib/parse-model-scaffold/templates/#{type}/*.ejs"

                        templates.each do |tmpl_file|

                            tmpl = File.read tmpl_file

                            erbTmpl = ERB.new tmpl

                            erbTmpl.result binding

                            tmpl_file = File.basename tmpl_file

                            output = erbTmpl.result binding

                            # Remove extenstion, and name propertly
                            tmpl_file.gsub!('template', @class_name).gsub!(File.extname(tmpl_file), '')



                            File.open(tmpl_file, 'w') { |file| file.write(output) }
                        end
                    end
                end

                def objc_attr_type(attr)
                    case attr.type
                    when :String, :Array
                        "NS#{attr.type}*"
                    when :Boolean
                        "BOOL"
                    when :Pointer
                        "PFObject*"
                    when :GeoPoint
                        "PFGeoPoint*"
                    when :Relation
                        "PFRelation*"
                    else
                        "?#{attr.type}?"
                    end
                end

                private

                def supported_types
                    @@supported_types
                end
            end
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parse-model-scaffold-0.0.1 lib/parse-model-scaffold/parse_class_builder.rb