Class: CapicuaGen::Gaspar::CSHeaderFooterFeature

Inherits:
TemplateFeature
  • Object
show all
Includes:
CapicuaGen, CapicuaGen::Gaspar
Defined in:
lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb

Overview

Caracteristica generadora de caceberas y pies de pagina en el codigo fuente generado por otras caracteristicas

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CapicuaGen::Gaspar

#get_about_class_full_name, #get_about_class_name, #get_app_config_file, #get_db_connection_name_method, #get_db_connection_provider_method, #get_db_connection_string_method, #get_entity_by_catalog_name, #get_entity_catalogs_full_name, #get_entity_catalogs_name, #get_entity_data_access_full_name, #get_entity_data_access_name, #get_entity_full_name, #get_entity_interface_full_name, #get_entity_interface_name, #get_entity_name, #get_main_form_class_full_name, #get_main_form_class_name, #get_namespaces, #get_namespaces_text, #get_splash_class_full_name, #get_splash_class_name

Constructor Details

#initialize(values = {}) ⇒ CSHeaderFooterFeature

Inicializa la caracteristica



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb', line 44

def initialize(values= {})
  super(values)

  # Configuro los tipos si estos no han sido configurados previamente
  self.types= [:code_transformer] if self.types.blank?

  # Configuro los templates
  set_template("header", Template.new(:file => 'header.erb'))
  set_template("footer", Template.new(:file => 'footer.erb'))

  #Configuro los include y exclude
  @include_regex= [/\.cs$/i] unless @include_regex
  @exclude_regex= [/\.Designer\.cs$/i] unless @exclude_regex


end

Instance Attribute Details

#exclude_regexObject

Returns the value of attribute exclude_regex.



39
40
41
# File 'lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb', line 39

def exclude_regex
  @exclude_regex
end

#include_regexObject

Returns the value of attribute include_regex.



39
40
41
# File 'lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb', line 39

def include_regex
  @include_regex
end

Instance Method Details

#check_include(file) ⇒ Object

Revisa si un archivo debe ser incluido



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb', line 128

def check_include(file)
  return false if @include_regex.blank?

  @include_regex.each do |include|
    return false unless include.match(file)
  end

  return true if @exclude_regex.blank?

  @exclude_regex.each do |exclude|
    return false if exclude.match(file)
  end

  return true

end

#configure_template_targetsObject

Configura los objetivos de las platillas (despues de establecer el generador)



62
63
64
65
66
67
68
# File 'lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb', line 62

def configure_template_targets

  # Configuro los templates
  @header_template_target= set_template_target('header', TemplateTarget.new())
  @footer_template_target= set_template_target('footer', TemplateTarget.new())

end

#generateObject

Recorre las plantilla y genera las cabeceras



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
# File 'lib/CapicuaGenGaspar/CodeTransformer/CSHeaderFooter/Source/cs_header_footer_feature.rb', line 71

def generate
  message_helper.puts_generating_feature(self)

  message_helper.add_indent

  begin


    resultado= ''

    template_target= get_template_target_by_name('proyect')

    directory_base= self.generation_attributes[:out_dir]
    # Recorro todas las caracteristicas
    generator.features().each do |feature|
      #Obtengo todos los archivos asociados
      feature.get_relative_out_files(:directory_base => directory_base, :types => :proyect_file).each do |unix_path|

        # Nombre del archivo
        file     = unix_path.gsub(/\//, '\\')
        file_name= File.basename file

        next unless check_include(file)

        file_content= ''

        Dir.chdir directory_base do
          # Cargo el acrhivo
          file_content= File.read(file)
        end


        # Genero los las licencias
        header= generate_template_target(@header_template_target, binding)
        return if not header.blank? and file_content.include?(header)
        footer= generate_template_target(@footer_template_target, binding)
        return if not footer.blank? and file_content.include?(footer)

        file_out= "#{header}#{file_content}#{footer}"
        Dir.chdir directory_base do
          # Guardo el archivo
          File.write(file, file_out)
          message_helper.puts_created_template("header.erb, footer.erb", file, :override)
        end
      end

    end

  ensure
    message_helper.remove_indent
    puts

  end

end